-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(balancer) do not send body from balancer ctx #2327
Conversation
The `kong.tools.responses` module sends a body with `ngx.say` when calling `responses.send_HTTP_SERVER_ERROR()`. This produces an error on top of a previous error, as in: ``` 2017/04/03 23:42:00 [error] 11076#0: *29 [lua] kong.lua:239: balancer(): failed to set the current peer (address:'2400:cb00:2048:1:0:0:681c:767' port:80): invalid port while connecting to upstream, client: 127.0.0.1, server: kong, request: "GET /status/200?apikey=secret123 HTTP/1.1", host: "acl_test1.com" 2017/04/03 23:42:00 [error] 11076#0: *29 failed to run balancer_by_lua*: ...he/luarocks-2.4.2/share/lua/5.1/kong/tools/responses.lua:127: API disabled in the context of balancer_by_lua* stack traceback: [C]: in function 'say' ...he/luarocks-2.4.2/share/lua/5.1/kong/tools/responses.lua:127: in function 'balancer' balancer_by_lua:2: in function <balancer_by_lua:1> while connecting to upstream, client: 127.0.0.1, server: kong, request: "GET /status/200?apikey=secret123 HTTP/1.1", host: "acl_test1.com"' ``` This is because, as pointed out in the error, `ngx.say` is not supported in the `balancer_by_lua` context. This logs the errors directly from the balancer context and simply sends the `500` status to the client.
@thibaultcha I'll have a look tomorrow, first thought: wouldn't the generic solution be to test in |
Not so sure, since this module is bound to disappear imo. With time, I regret ever implementing it, since I'd much rather favor explicitness and avoid black boxes for the core. Plugins can use such a module (rewritten as part of the Public Lua API, this one should be considered legacy), but I believe the core should not and should use the raw OR Lua API. |
I don't agree to that. That module has some logic (like 500's not leaking any info, and default messages). Also this logic, not using It would be asking for trouble imo. |
Considering i18n and custom error messages pending, we should probably postpone this design decision until we actually get to refactoring |
I don't mean duplicating it all over the place, but rather do less "black box" things that we have no control of from the caller's POV and that is taking the proper OR API we want to manipulate out of its reach (setting headers, arbitrary logging, arbitrary content-type setting or body encoding, arbitrary exit code, etc, etc...). BTW, it might be worth noting that this patch still uses the I am not opposed to making the |
Summary
The
kong.tools.responses
module sends a body withngx.say
whencalling
responses.send_HTTP_SERVER_ERROR()
. This produces an error ontop of a previous error, as in:
This is because, as pointed out in the error,
ngx.say
is not supportedin the
balancer_by_lua
context.This logs the errors directly from the balancer context and simply sends
the
500
status to the client.