You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/07/04 12:35:40 UTC

[GitHub] [apisix] ctgpf opened a new issue #4529: request help: curl hangs indefinitely when accessing REST Admin API from Serverless plugin

ctgpf opened a new issue #4529:
URL: https://github.com/apache/apisix/issues/4529


   ### Issue description
   Hello all,
   
   I'm trying to use this simple lua function in serverless plugin:
   ```
   "plugins": {
       "serverless-post-function": {
         "disable": false,
         "functions": [
           "return function()  ngx.log(ngx.ERR, \"BEGIN:\"); os.execute('curl http://127.0.0.1:9180/apisix/admin/plugins/list -H \"X-API-KEY: edd1c9f034335f136f87ad84b625c8f1\"'); ngx.log(ngx.ERR, \"END:\"); end"
         ],
         "phase": "body_filter"
       }
     }
   ```
   But when testing, the curl command hangs indefinitely and never ends... 
   
   Here are some debug information:
   
   > **# strace -p <curl_PID>**
   > poll([{fd=4, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
   > poll([{fd=4, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
   > ...
   > poll([{fd=4, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
   > poll([{fd=4, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
   
   So the curl is waiting for the fd 4 to become ready, but timeout.
   
   > **# ls -l /proc/<curl_PID>/fd**
   > 4 -> socket:[91241]
   > **# lsof -p <PID> |grep 91241**
   > TCP localhost:49198->localhost:9180 (ESTABLISHED)
   
   So the socket is opened and the tcpdump shows that the GET method is indeed sent. But no response from the REST Admin API.
   
   For information, os.execute('curl http://127.0.0.1:9180/apisix/admin/plugins/list -H \"X-API-KEY: edd1c9f034335f136f87ad84b625c8f1\" **&**'); with the '&' at the end works, but I want to wait until curl finishes instead of launching in background.
   
   Setting the timeout option to curl, os.execute('curl **-m 3** http://...') triggers the timeout in apisix error.log:
   > curl: (28) Operation timed out after 3001 milliseconds with 0 out of -1 bytes received
   
   I have tried other methods, but they failed too:
   - wget instead of curl
   - io.popen() instead of os.execute()
   
   Can someone please know how to make it work?
   
   ### Environment
   
   Request help without environment information will be ignored or closed.
   
   * apisix version (cmd: `apisix version`): 2.6
   * OS (cmd: `uname -a`): Linux localhost.localdomain 3.10.0-1160.31.1.el7.x86_64 #1 SMP Thu Jun 10 13:32:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
   * OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`): nginx version: openresty/1.19.3.2
   * etcd version, if have (cmd: run `curl http://127.0.0.1:9090/v1/server_info` to get the info from server-info API): "etcd_version":"3.5.0"
   * apisix-dashboard version, if have: 2.7
   * luarocks version, if the issue is about installation (cmd: `luarocks --version`): 3.4.0
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on issue #4529: request help: curl hangs indefinitely when accessing REST Admin API from Serverless plugin

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #4529:
URL: https://github.com/apache/apisix/issues/4529#issuecomment-873707012


   What about using lua-resty-http? It uses cosocket so it won't block the Nginx.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] ctgpf closed issue #4529: request help: curl hangs indefinitely when accessing REST Admin API from Serverless plugin

Posted by GitBox <gi...@apache.org>.
ctgpf closed issue #4529:
URL: https://github.com/apache/apisix/issues/4529


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] ctgpf commented on issue #4529: request help: curl hangs indefinitely when accessing REST Admin API from Serverless plugin

Posted by GitBox <gi...@apache.org>.
ctgpf commented on issue #4529:
URL: https://github.com/apache/apisix/issues/4529#issuecomment-873831937


   Thank you for your answer! 
   
   I tried using lua-resty-http and I got an explicit error:  API disabled in the context of body_filter_by_lua*.
   Actually, cosocket is disabled in this context, which probably explains why it was blocking.
   
   In fact, my idea was to use the REST Admin API to dynamically create routes if I got an HTTP/200 response from an auth API upstream and I thought body_filter was the right context. But due to this limitation, I will change my logic and do the work in the access context, since cosocket is enabled there.
   
   Thank you again @spacewander!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org