Then you will see something like this in the corresponding error.log:
2017/08/02 16:37:50 [error] 21399#21399: *3 lua entry thread aborted: runtime error: content_by_lua(nginx.conf:42):3: no request ctx found
stack traceback:
coroutine 0:
[C]: in function 'flush'
content_by_lua(nginx.conf:42):3: in function <content_by_lua(nginx.conf:42):1>, client: 127.0.0.1, server: _, request: "GET / HTTP/1.1", host: "127.0.0.1:8081"
After reading the related codes, i find the problem is caused by ngx_http_not_modified_header_filter at the earliest, which jumps to ngx_http_filter_finalize_request when ngx_http_test_if_unmodified returns 0, and ngx_http_filter_finalize_request cleans ctx of all the http modules, sets r->filter_finalize to 1.
Then we calling ngx.flush, we will get the provious runtime error because the ctx of ngx_lua is cleaned.
Maybe we should set the ctx of ngx_lua when r->filter_finalize is equal to 1 in ngx_http_lua_ngx_flush, like ngx_http_lua_handle_exit and others? Or we can mark it in the doc?
Hi!
I found
ngx.flush
throws a Lua runtime error after thengx.print
was called by accident.you can reproduce the problem by the following nginx configuration.
Then you will see something like this in the corresponding
error.log
:After reading the related codes, i find the problem is caused by
ngx_http_not_modified_header_filter
at the earliest, which jumps tongx_http_filter_finalize_request
whenngx_http_test_if_unmodified
returns 0, andngx_http_filter_finalize_request
cleans ctx of all the http modules, setsr->filter_finalize
to 1.Then we calling
ngx.flush
, we will get the provious runtime error because the ctx of ngx_lua is cleaned.Maybe we should set the ctx of ngx_lua when
r->filter_finalize
is equal to 1 inngx_http_lua_ngx_flush
, likengx_http_lua_handle_exit
and others? Or we can mark it in the doc?I am sorry if something i describe is not clear.