Fixing ngx_http_slice_module use with named locations
Roman Arutyunyan
arut at nginx.com
Thu Feb 16 15:44:11 UTC 2017
Hello Mindaugas,
On Wed, May 04, 2016 at 02:20:30PM +0100, Mindaugas Rasiukevicius wrote:
> Hi,
>
> There is a problem with ngx_http_slice_module when it is used together
> with an internal redirection to a named location. It results in Nginx
> workers caching incorrect content and spinning in an infinite loop.
> Consider the following fragment:
>
> location /foo {
> error_page 550 = @bar;
> return 550;
> }
> location @bar {
> slice ...;
> proxy_pass ...;
> proxy_cache ...;
> ...
> }
>
> In ngx_http_slice_body_filter(), the slice context is associated with
> the subrequest:
>
> ngx_http_set_ctx(sr, ctx, ngx_http_slice_filter_module);
>
> However, the location re-match is triggered for the subrequests trying
> to fetch each slice. In the ngx_http_named_location() function:
>
> /* clear the modules contexts */
> ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
>
> So, the slice context gets lost. There are several ways to fix this.
> Unless you want an API to preserve the context, one simple fix would be
> to get the context via r->parent (if ctx == NULL && r != r->main).
>
> What would be the preferred way to fix this?
We have fixed the issue in http://hg.nginx.org/nginx/rev/d16ba0ea3434
Thanks for reporting this.
--
Roman Arutyunyan
More information about the nginx-devel
mailing list