missing module context

Valentin V. Bartenev ne at vbart.ru
Tue Jul 10 10:24:54 UTC 2012


On Tuesday 10 July 2012 14:17:11 Valentin V. Bartenev wrote:
> On Tuesday 10 July 2012 12:31:45 Anatoli Marinov wrote:
> > Hello Colleagues,
> > I am working on a project, that uses nginx as http proxy and I have
> > written many nginx modules. For several months till now I am looking for
> > a bug in one of my modules but I cannot find it. It appears very rare
> > but even so it should be fixed.
> > 
> > I added many log messages to debug the issue. I found that some time the
> > module context is null even it has been set before.  I am using context
> > functions as usual:
> > 1. In rewrite phase :
> > ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_my_ctx_t));
> > ngx_http_set_ctx(r, ctx, ngx_http_my_module);
> > 
> > 2. In log phase I am trying to get back my context :
> > ctx = ngx_http_get_module_ctx(r, ngx_http_my_module);
> > In this place ctx is NULL.
> > 
> > What is your opinion? Am am using this sequence on many places and it
> > works as I expected but in this modules sometimes it fails.
> > I think there could be a memory corruption issue. There could be a code
> > that may write on request's context array and overwrite the context
> > pointer. Is there a way to check this? Nginx uses its own memory pool
> > system and tools like valgrind is not longer usable.
> > 
> > Please advise me how to find this issue...
> > 
> > All ideas are welcome!
> > Best Regards
> 
> The request context doesn't shared between subrequests. If you set ctx for
> subrequest and then trying to retrieve it for main request you will get
> NULL.
> 

Btw, it also cleared by the internal redirect.

 wbr, Valentin V. Bartenev



More information about the nginx-devel mailing list