Hello Yichin,
On 03/05/2015 11:15 PM, Yichun Zhang (agentzh) wrote:
Hello!
> They're separate and different ngx_http_request_t structs and pointers.
Surely you can demonstrate it to me, right?
> Unfortunately, I don't see any way to do it - it's the same request, so the
> location config is the same, too.
>
> Here's an excerpt from GDB trace:
> ngx_http_lua_subrequest (r=0x118a060 <--- NB
> ngx_http_jpegresize_header_filter (r=0x118a060
> ngx_http_jpegresize_body_filter (r=0x118a060
> ngx_http_jpegresize_header_filter (r=0x118a060
> ngx_http_jpegresize_body_filter (r=0x118a060
>
> From this backtrace, I wonder how *your* header filter calls into *your* body filter in the first place
I'm sorry for not being clear enough, but I said this is only an excerpt.
No, header_filter doesn't call body_filter, it's the breakpoints that are triggered in exactly this sequence.
See my first email for a bit more detailed traces.
> and also how your body filter can in turn call into your header filter. This looks more like an issue in your own filter module to me.
> Maybe you should arm yourself with more basic nginx programming knowledge first :)
Ok, I've removed our custom module completely and added standard image_filter module instead.
And I can still reproduce the bug, see sample config and gdb traces below.
Note that there is no second image_body_filter call because image_filter resets its location context
on the second header_filter call (because it doesn't expect it to be called twice in the same request).
Apparently, its author also should go read a book and learn some basic nginx programming practices.
Sample config for image_filter:
-----------
location ~ /backend/ {
root /;
try_files /local/nginx/html/image.jpg = 404;
}
location ~ /get/ {
image_filter resize 150 100; # yes, I want to get original image in Lua and then resize it
image_filter rotate 90; # so the filter has to be here, not in the section above
content_by_lua '
local res = ngx.location.capture("/backend/")
for k, v in pairs(res.header) do
ngx.header[k] = v
end
ngx.status = res.status
ngx.print(res.body)
';
}
-----------
gdb traces (all during the same request to /get/):
1)
#0 ngx_http_image_header_filter (r=0xa69060) at src/http/modules/ngx_http_image_filter_module.c:214
#1 0x00000000004e26ef in ngx_http_userid_filter (r=0xa69060) at src/http/modules/ngx_http_userid_filter_module.c:209
#2 0x000000000051b7ae in ngx_http_cc_header_filter (r=0xa69060) at ../ngx_http_cc_module.git/ngx_http_cc_module.c:909
#3 0x00000000004ccfe9 in ngx_http_headers_filter (r=0xa69060) at src/http/modules/ngx_http_headers_filter_module.c:167
#4 0x00000000005558a5 in ngx_http_lua_capture_header_filter (r=0xa69060) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_capturefilter.c:108
#5 0x00000000004ce098 in ngx_http_not_modified_header_filter (r=0xa69060) at src/http/modules/ngx_http_not_modified_filter_module.c:108
#6 0x0000000000496fa0 in ngx_http_send_header (r=0xa69060) at src/http/ngx_http_core_module.c:1956
#7 0x000000000054bfd8 in ngx_http_lua_send_header_if_needed (r=0xa69060, ctx=0xac28d0) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_util.c:429
#8 0x000000000054c0fc in ngx_http_lua_send_chain_link (r=0xa69060, ctx=0xac28d0, in=0xac4490) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_util.c:469
#9 0x0000000000538e05 in ngx_http_lua_ngx_echo (L=0xa6a5f0, newline=0) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_output.c:224
#10 0x00000000005386fb in ngx_http_lua_ngx_print (L=0xa6a5f0) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_output.c:25
#11 0x0000000000574718 in luaD_precall ()
#12 0x000000000057d407 in luaV_execute ()
#13 0x0000000000573ec8 in luaD_rawrunprotected ()
#14 0x0000000000574b8b in lua_resume ()
#15 0x000000000054d165 in ngx_http_lua_run_thread (L=0xae5a90, r=0xa69060, ctx=0xac28d0, nrets=1) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_util.c:1000
#16 0x0000000000533844 in ngx_http_lua_subrequest_resume (r=0xa69060) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_subrequest.c:1591
#17 0x000000000055344a in ngx_http_lua_content_wev_handler (r=0xa69060) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_contentby.c:131
2)
#0 ngx_http_image_body_filter (r=0xa69060, in=0xac4490) at src/http/modules/ngx_http_image_filter_module.c:287
#1 0x0000000000555974 in ngx_http_lua_capture_body_filter (r=0xa69060, in=0xac4490) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_capturefilter.c:132
#2 0x0000000000457d24 in ngx_output_chain (ctx=0xac4628, in=0xac4490) at src/core/ngx_output_chain.c:66
#3 0x00000000004aca8f in ngx_http_copy_filter (r=0xa69060, in=0xac4490) at src/http/ngx_http_copy_filter_module.c:143
#4 0x00000000004cc233 in ngx_http_range_body_filter (r=0xa69060, in=0xac4490) at src/http/modules/ngx_http_range_filter_module.c:594
#5 0x000000000049702a in ngx_http_output_filter (r=0xa69060, in=0xac4490) at src/http/ngx_http_core_module.c:1971
#6 0x000000000054c453 in ngx_http_lua_output_filter (r=0xa69060, in=0xac4490) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_util.c:588
#7 0x000000000054c361 in ngx_http_lua_send_chain_link (r=0xa69060, ctx=0xac28d0, in=0xac4490) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_util.c:543
#8 0x0000000000538e05 in ngx_http_lua_ngx_echo (L=0xa6a5f0, newline=0) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_output.c:224
#9 0x00000000005386fb in ngx_http_lua_ngx_print (L=0xa6a5f0) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_output.c:25
#10 0x0000000000574718 in luaD_precall ()
#11 0x000000000057d407 in luaV_execute ()
#12 0x0000000000573ec8 in luaD_rawrunprotected ()
#13 0x0000000000574b8b in lua_resume ()
#14 0x000000000054d165 in ngx_http_lua_run_thread (L=0xae5a90, r=0xa69060, ctx=0xac28d0, nrets=1) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_util.c:1000
#15 0x0000000000533844 in ngx_http_lua_subrequest_resume (r=0xa69060) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_subrequest.c:1591
#16 0x000000000055344a in ngx_http_lua_content_wev_handler (r=0xa69060) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_contentby.c:131
3)
#0 ngx_http_image_header_filter (r=0xa69060) at src/http/modules/ngx_http_image_filter_module.c:214
#1 0x00000000004e26ef in ngx_http_userid_filter (r=0xa69060) at src/http/modules/ngx_http_userid_filter_module.c:209
#2 0x000000000051b7ae in ngx_http_cc_header_filter (r=0xa69060) at ../ngx_http_cc_module.git/ngx_http_cc_module.c:909
#3 0x00000000004ccfe9 in ngx_http_headers_filter (r=0xa69060) at src/http/modules/ngx_http_headers_filter_module.c:167
#4 0x00000000005558a5 in ngx_http_lua_capture_header_filter (r=0xa69060) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_capturefilter.c:108
#5 0x00000000004ce098 in ngx_http_not_modified_header_filter (r=0xa69060) at src/http/modules/ngx_http_not_modified_filter_module.c:108
#6 0x0000000000496fa0 in ngx_http_send_header (r=0xa69060) at src/http/ngx_http_core_module.c:1956
#7 0x000000000054bfd8 in ngx_http_lua_send_header_if_needed (r=0xa69060, ctx=0xac28d0) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_util.c:429
#8 0x000000000054c0fc in ngx_http_lua_send_chain_link (r=0xa69060, ctx=0xac28d0, in=0x0) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_util.c:469
#9 0x000000000054e0e8 in ngx_http_lua_run_thread (L=0xae5a90, r=0xa69060, ctx=0xac28d0, nrets=1) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_util.c:1468
#10 0x0000000000533844 in ngx_http_lua_subrequest_resume (r=0xa69060) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_subrequest.c:1591
#11 0x000000000055344a in ngx_http_lua_content_wev_handler (r=0xa69060) at ../lua-nginx-module-0.9.14/src/ngx_http_lua_contentby.c:131
--
Wbr,
Antony Dovgal
---
http://pinba.org - realtime profiling for PHP