[PATCH] resetting write event handler in ngx_http_named_location

agentzh agentzh at gmail.com
Wed May 2 15:04:08 UTC 2012


Hello!

drdrxp has found a hanging problem when using ngx_eval in a named
location which is internal redirected to at content phase:

    https://github.com/agentzh/nginx-eval-module/pull/1

And we've found it is related to an issue in ngx_http_named_location
which could affect a wide range of different nginx modules. This issue
still exists in nginx 1.2.0.

Below is a patch (for nginx 1.0.15) to fix it by resetting
r->write_event_handler to ngx_http_core_run_phases, just as in
ngx_http_internal_redirect. The patch is needed because when
ngx_http_named_location is called from within the content phase,
r->write_event_handler is reset to ngx_http_request_empty_handler in
ngx_http_core_content_phase, or other content handlers may override it
to other things too.

Hopefully this issue can be fixed in the official core.

Thanks!
-agentzh

--- nginx-1.0.15/src/http/ngx_http_core_module.c        2012-03-05
21:03:39.000000000 +0800
+++ nginx-1.0.15-patched/src/http/ngx_http_core_module.c
2012-05-02 21:57:40.624937882 +0800
@@ -2567,6 +2567,8 @@

             r->phase_handler = cmcf->phase_engine.location_rewrite_index;

+            r->write_event_handler = ngx_http_core_run_phases;
+
             ngx_http_core_run_phases(r);

             return NGX_DONE;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginx-1.0.15-reset_wev_handler_in_named_locations.patch
Type: application/octet-stream
Size: 418 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20120502/3cc1ddc6/attachment.obj>


More information about the nginx-devel mailing list