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 2020/07/10 08:46:54 UTC

[GitHub] [incubator-apisix] moorefu opened a new issue #1826: bug: ngx.location.capture could not work on route

moorefu opened a new issue #1826:
URL: https://github.com/apache/incubator-apisix/issues/1826


   ### Issue description
   
   
   ### Environment
   
   * apisix version (cmd: `apisix version`):1.3
   * OS: CentOS Linux release 7.8.2003 (Core)
   *  Kernel: 3.10.0-1127.el7.x86_64
   
   ### Minimal test code / Steps to reproduce the issue
   1. create a new serverless route
   ```bash
   curl -i http://127.0.0.1:9080/apisix/admin/routes/1  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   {
       "uris": ["/real/abc.json"],
       "plugins": {
           "serverless-pre-function": {
               "phase": "rewrite",
               "functions" : ["return function() ngx.say(\"ok\"); end"]
           }
       },
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "39.97.63.215:80": 1
           }
       }
   }'
   ```
   2. create new plugin: process.lua
   ```lua
   local ngx           = ngx
     local ngx_capture   = ngx.location.capture
     local _M = {
       version = 0.1,
       priority = 9909,     
       type = 'process',   
       name = "process",
       schema = schema,
     }
     function _M.access(conf, ctx)
       local res = ngx_capture("/real/abc.json",{share_all_vars = true,ctx = ngx.ctx})
       return res.status_code,res.body
     end
   return _M
   ```
   
   3. create a process route
   
     ```
     curl -i http://127.0.0.1:9080/apisix/admin/routes/2  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
     {
         "uris": ["/process/abc.json"],
         "plugins": {
             "process": {}
         },
         "upstream": {
             "type": "roundrobin",
             "nodes": {
                 "39.97.63.215:80": 1
             }
         }
     }'
     ```
   
   4. get result
   
      `curl -i http://127.0.0.1:9080/process/abc.json`
   
      `curl -i http://127.0.0.1:9080/real/abc.json`
   
   ### What's the actual result? (including assertion message & call stack if applicable)
   first time had not pass opts to capture function。I got an errorlog
   `2020/07/09 23:31:44 [error] 20425#20425: *644502 [lua] init.lua:494: http_balancer_phase(): invalid api_ctx while connecting to upstream, client: 192.168.11.69, server: , request: "GET /process/abc HTTP/1.1", subrequest: "/real/abc", host: "192.168.11.13"`
   and then i pass a opts as under,then the error log gone.
   `{share_all_vars = true,ctx = ngx.ctx}`
   
   request the /real/abc.json ,got `ok`, what is the expected. 
   
   but request the  /process/abc.json, got nothing response body is empty.
   
   ### What's the expected result?
   
     ````
   expected result is what the real(/real/abc.json) response ok. 
     ````


----------------------------------------------------------------
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.

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



[GitHub] [incubator-apisix] membphis commented on issue #1826: bug: ngx.location.capture could not work on route

Posted by GitBox <gi...@apache.org>.
membphis commented on issue #1826:
URL: https://github.com/apache/incubator-apisix/issues/1826#issuecomment-656573898


   or you can make a try `local res = ngx_capture("/real/abc.json",{share_all_vars = true})`, you can not pass the current `ctx` directly.


----------------------------------------------------------------
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.

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



[GitHub] [incubator-apisix] membphis commented on issue #1826: bug: ngx.location.capture could not work on route

Posted by GitBox <gi...@apache.org>.
membphis commented on issue #1826:
URL: https://github.com/apache/incubator-apisix/issues/1826#issuecomment-656606944


   for `ngx.location.capture`, the sub-request only run `rewrite_by_lua_block` phase, but APISIX only use `access_by_lua_block` now.
   
   I advise you to use `resty-http`, it is a safer way.


----------------------------------------------------------------
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.

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



[GitHub] [incubator-apisix] moorefu commented on issue #1826: bug: ngx.location.capture could not work on route

Posted by GitBox <gi...@apache.org>.
moorefu commented on issue #1826:
URL: https://github.com/apache/incubator-apisix/issues/1826#issuecomment-657927473


   > for `ngx.location.capture`, the sub-request only run `rewrite_by_lua_block` phase, but APISIX only use `access_by_lua_block` now.
   > 
   > I advise you to use `resty-http`, it is a safer way.
   
   thanks, I use the `resty-http` finally, and it work well.


----------------------------------------------------------------
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.

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



[GitHub] [incubator-apisix] membphis commented on issue #1826: bug: ngx.location.capture could not work on route

Posted by GitBox <gi...@apache.org>.
membphis commented on issue #1826:
URL: https://github.com/apache/incubator-apisix/issues/1826#issuecomment-656572958


   you can take a look at: https://github.com/apache/incubator-apisix/blob/master/doc/plugins/batch-requests.md


----------------------------------------------------------------
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.

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



[GitHub] [incubator-apisix] moonming closed issue #1826: bug: ngx.location.capture could not work on route

Posted by GitBox <gi...@apache.org>.
moonming closed issue #1826:
URL: https://github.com/apache/incubator-apisix/issues/1826


   


----------------------------------------------------------------
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.

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



[GitHub] [incubator-apisix] membphis edited a comment on issue #1826: bug: ngx.location.capture could not work on route

Posted by GitBox <gi...@apache.org>.
membphis edited a comment on issue #1826:
URL: https://github.com/apache/incubator-apisix/issues/1826#issuecomment-656573898


   or you can make a try `local res = ngx_capture("/real/abc.json",{share_all_vars = true})`, you can not pass the current `ctx` directly. it is unsafe for APISIX.


----------------------------------------------------------------
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.

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



[GitHub] [incubator-apisix] moorefu commented on issue #1826: bug: ngx.location.capture could not work on route

Posted by GitBox <gi...@apache.org>.
moorefu commented on issue #1826:
URL: https://github.com/apache/incubator-apisix/issues/1826#issuecomment-656577593


   yes, i found the http_balancer_phase use the api_ctx. and i will init in http_access_phase. so i guess the ngx.location.capture will not execue the http_access_phase.
   btw:
   i will do some process with the request body and response body by a wrapper way. and the real route can work by it's way(include upstreams、plugins、etc), so i try the capture funciton.


----------------------------------------------------------------
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.

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



[GitHub] [incubator-apisix] moorefu commented on issue #1826: bug: ngx.location.capture could not work on route

Posted by GitBox <gi...@apache.org>.
moorefu commented on issue #1826:
URL: https://github.com/apache/incubator-apisix/issues/1826#issuecomment-656582432


   > or you can make a try `local res = ngx_capture("/real/abc.json",{share_all_vars = true})`, you can not pass the current `ctx` directly. it is unsafe for APISIX.
   
   yes i try this way also.but the real route do not work.and got error log.
   `2020/07/09 23:31:44 [error] 20425#20425: *644502 [lua] init.lua:494: http_balancer_phase(): invalid api_ctx while connecting to upstream, client: 192.168.11.69, server: , request: "GET /process/abc HTTP/1.1", subrequest: "/real/abc", host: "192.168.11.13"`


----------------------------------------------------------------
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.

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



[GitHub] [incubator-apisix] moorefu edited a comment on issue #1826: bug: ngx.location.capture could not work on route

Posted by GitBox <gi...@apache.org>.
moorefu edited a comment on issue #1826:
URL: https://github.com/apache/incubator-apisix/issues/1826#issuecomment-656577593


   yes, i found the http_balancer_phase use the api_ctx. and it will init in http_access_phase. so i guess the ngx.location.capture will not execue the http_access_phase.
   btw:
   i will do some process with the request body and response body by a wrapper way. and the real route can work by it's way(include upstreams、plugins、etc), so i try the capture funciton.


----------------------------------------------------------------
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.

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