lua-nginx-module icon indicating copy to clipboard operation
lua-nginx-module copied to clipboard

HTTP/2 protocol error if headers are sent before a Lua error

Open LoganDark opened this issue 3 years ago • 2 comments

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.

LoganDark avatar Apr 10 '22 23:04 LoganDark

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

LoganDark avatar Apr 11 '22 07:04 LoganDark

because the header has been sent out and there is no chance to change the HTTP status. So close the connection directly.

zhuizhuhaomeng avatar Apr 14 '22 13:04 zhuizhuhaomeng