You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "zhendongcmss (via GitHub)" <gi...@apache.org> on 2023/06/01 01:53:25 UTC

[GitHub] [apisix] zhendongcmss opened a new issue, #9585: bug: ngx.exit() doesn't support header_filter_by_lua

zhendongcmss opened a new issue, #9585:
URL: https://github.com/apache/apisix/issues/9585

   ### Current Behavior
   
   - I want close the connection on header_filter_by_lua phase, I add the code on `apisix/plugins/response-rewrite.lua` to test it.
   
   ```
   function _M.header_filter(conf, ctx)
       if true then
           ngx.header.connection = "close"
           ngx.status = 444
           ngx.exit(444)
           return
       end
   ...
   ```
   
   - Test it, the connection was closed.
   
   ```
   curl 127.0.0.1:9080/test/ -i
   curl: (52) Empty reply from server
   ```
   
   
   - But I got error
   
   error.log
   ```
   2023/06/01 09:46:47 [error] 22431#22431: *596 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: _, request: "GET /test/ HTTP/1.1", upstream: "http://127.0.0.1:8881/test/", host: "127.0.0.1:9080"
   2023/06/01 09:46:47 [error] 22431#22431: *596 attempt to set ngx.header.HEADER after sending out response headers while sending to client, client: 127.0.0.1, server: _, request: "GET /test/ HTTP/1.1", upstream: "http://127.0.0.1:8881/test/", host: "127.0.0.1:9080"
   2023/06/01 09:46:47 [error] 22431#22431: *596 failed to run body_filter_by_lua*: ...ncer-upstream-groups/apisix/plugins/response-rewrite.lua:128: API disabled in the context of body_filter_by_lua*
   stack traceback:
       [C]: in function 'error'
       /usr/local/openresty/lualib/resty/core/exit.lua:60: in function 'exit'
       ...ncer-upstream-groups/apisix/plugins/response-rewrite.lua:128: in function 'phase_func'
       ...working/onest-balancer-upstream-groups/apisix/plugin.lua:708: in function 'run_plugin'
       ...working/onest-balancer-upstream-groups/apisix/plugin.lua:741: in function 'run_global_rules'
       ...4_working/onest-balancer-upstream-groups/apisix/init.lua:342: in function 'common_phase'
       ...4_working/onest-balancer-upstream-groups/apisix/init.lua:641: in function 'http_body_filter_phase'
       body_filter_by_lua:2: in main chunk while sending to client, client: 127.0.0.1, server: _, request: "GET /test/ HTTP/1.1", upstream: "http://127.0.0.1:8881/test/", host: "127.0.0.1:9080"
   ```
   
   - The lua-nginx-module say ngx.exit() can be used on header_filter_by_lua. https://github.com/openresty/lua-nginx-module#ngxexit
   syntax: ngx.exit(status)
   
   context: rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*
   
   - I try on 2.10.1 and master branch both have this issue.
   
   ### Expected Behavior
   
   _No response_
   
   ### Error Logs
   
   _No response_
   
   ### Steps to Reproduce
   
   refer Current Behavior
   
   ### Environment
   
   - APISIX version (run `apisix version`): 2.10.1 and mster branch
   - Operating system (run `uname -a`): centos 7.9
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`): nginx version: openresty/1.19.3.2
   - etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`):
   - APISIX Dashboard version, if relevant:
   - Plugin runner version, for issues related to plugin runners:
   - LuaRocks version, for installation issues (run `luarocks --version`):
    


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

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


[GitHub] [apisix] zhendongcmss commented on issue #9585: bug: ngx.exit() doesn't support header_filter_by_lua

Posted by "zhendongcmss (via GitHub)" <gi...@apache.org>.
zhendongcmss commented on issue #9585:
URL: https://github.com/apache/apisix/issues/9585#issuecomment-1577990670

   > Although according to the documentation it shouldn't happen so I am looking into it. Meanwhile you can use ngx.ctx to signal completion. Set ngx.ctx.request_complete = true in header_filter after exiting. Then check if ngx.ctx.done in body_filter before moving forward. Though it feels like a hack and there must be a better solution
   
   ngx.exit() or ngx.eof() both don't support filter_body.


-- 
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] Revolyssup commented on issue #9585: bug: ngx.exit() doesn't support header_filter_by_lua

Posted by "Revolyssup (via GitHub)" <gi...@apache.org>.
Revolyssup commented on issue #9585:
URL: https://github.com/apache/apisix/issues/9585#issuecomment-1621086829

   @zhendongcmss As mentioned here - https://openresty-reference.readthedocs.io/en/latest/Lua_Nginx_API/#ngxexit
   If ngx.status == OK, then only the current phase is terminated and the request goes through rest of the phases, like it did here. 


-- 
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] lingsamuel closed issue #9585: bug: ngx.exit() doesn't support header_filter_by_lua

Posted by "lingsamuel (via GitHub)" <gi...@apache.org>.
lingsamuel closed issue #9585: bug: ngx.exit() doesn't support header_filter_by_lua
URL: https://github.com/apache/apisix/issues/9585


-- 
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] zhendongcmss commented on issue #9585: bug: ngx.exit() doesn't support header_filter_by_lua

Posted by "zhendongcmss (via GitHub)" <gi...@apache.org>.
zhendongcmss commented on issue #9585:
URL: https://github.com/apache/apisix/issues/9585#issuecomment-1571223553

   if `ngx.exit(444)` work on `function _M.header_filter(conf, ctx)` , `function _M.body_filter(conf, ctx)` shouldn't be executed.


-- 
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] Revolyssup commented on issue #9585: bug: ngx.exit() doesn't support header_filter_by_lua

Posted by "Revolyssup (via GitHub)" <gi...@apache.org>.
Revolyssup commented on issue #9585:
URL: https://github.com/apache/apisix/issues/9585#issuecomment-1573138757

   Although according to the documentation it shouldn't happen so I am looking into it. Meanwhile you can use ngx.ctx to signal completion. Set ngx.ctx.request_complete = true in header_filter after exiting. Then check if ngx.ctx.done in body_filter before moving forward. Though it feels like a hack and there must be a better solution


-- 
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] Revolyssup commented on issue #9585: bug: ngx.exit() doesn't support header_filter_by_lua

Posted by "Revolyssup (via GitHub)" <gi...@apache.org>.
Revolyssup commented on issue #9585:
URL: https://github.com/apache/apisix/issues/9585#issuecomment-1645065610

   @zhendongcmss By default, even if you call ngx.exit() in the header filter, the body filter will still be executed. This is not a bug. We can close this issue. Please don't use ngx.exit in body filter.
   


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