lua-nginx-module
lua-nginx-module copied to clipboard
HTTP/2 protocol error if headers are sent before a Lua error
Relevant section of the OpenResty 1.19.9.1 config:
location @error {
content_by_lua_file /var/www/lua/error.lua;
}
location / {
error_page 500 @error;
content_by_lua_file /var/www/lua/content.lua;
}
error.lua:
ngx.say(tostring(ngx.status))
content.lua:
ngx.send_headers()
error('hi')
Trying to curl https://localhost results in:
curl: (92) HTTP/2 stream 0 was not closed cleanly: INTERNAL_ERROR (err 2)
curl https://localhost --http1.1 (or --http1.0):
curl: (52) Empty reply from server
Commenting out the call to ngx.send_headers() results in the request completing successfully and printing 500.
Using echo instead of content_by_lua* in the @error named location doesn't solve the issue.
ugh I'm just generally having issues whenever multiple phases are involved. i.e. calling ngx.exit from access_by_lua_file also causes invalid responses. ngx.exec mostly works though
because the header has been sent out and there is no chance to change the HTTP status. So close the connection directly.