[PATCH] clear modules' contexts in ngx_http_named_location

Maxim Dounin mdounin at mdounin.ru
Thu Oct 13 19:24:15 UTC 2011


Hello!

On Thu, Oct 13, 2011 at 03:10:25PM +0800, agentzh wrote:

> Hello!
> 
> Here attaches a patch for the nginx 1.1.5 core to fix a long standing
> bug in the ngx_http_named_location function.
> 
> I think we should clear out all the modules' contexts there just as in
> ngx_http_internal_redirect, or we'll observe weird issues due to
> left-over obsolete module contexts from the original request before
> the jump. Here is a bad case in action:
> http://www.ruby-forum.com/topic/2765027
> 
> Regards,
> -agentzh
> 
> --- nginx-1.1.5/src/http/ngx_http_core_module.c	2011-09-27
> 19:14:02.000000000 +0800
> +++ nginx-1.1.5-patched/src/http/ngx_http_core_module.c	2011-10-13
> 15:02:24.414550532 +0800
> @@ -2542,6 +2542,9 @@
>              r->content_handler = NULL;
>              r->loc_conf = (*clcfp)->loc_conf;
> 
> +            /* clear the modules contexts */
> +            ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
> +
>              ngx_http_update_location_config(r);
> 
>              cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);

I think this is a right change.

To Igor: previous discussion I was able to find is here (in 
Russian):

http://mailman.nginx.org/pipermail/nginx-ru/2009-July/026730.html

Since then, I can't recall any single case where not clearing 
module contexts was beneficial.  On the other hand, the above case 
is at least 2nd one when it strikes badly.

Maxim Dounin



More information about the nginx-devel mailing list