[PATCH] nginx does not close the connection for 412 responses under extreme conditions
Maxim Dounin
mdounin at mdounin.ru
Sat May 12 08:50:54 UTC 2012
Hello!
On Fri, May 11, 2012 at 08:59:48PM +0800, agentzh wrote:
> Hello!
>
> I've just noticed that the "412 Precondition Failed page" for the
> If-Unmodified-Since request header could lead to connection hang. That
> is, when the 412 page cannot be sent out in a single run (seen EAGAIN
> for example), then ngx_http_finalize_request will never close the
> downstream connection due to the r->filter_finalize set by
> ngx_http_filter_finalize_request.
>
> This issue can be reproduced with the standard ngx_http_static_module
> serving the sample index.html page.
Could you please clarify steps to reproduce you've used? The only
way I see is to redirect 412 error to an uncached static file with
aio used, thus causing r->blocked to be set during request
finalization.
> Here attaches the patch for both nginx 1.0.15 to fix this (it should
> also be applied to nginx 1.2.0, I think).
>
> Comments welcome!
>
> Thanks!
> -agentzh
>
> --- nginx-1.0.15/src/http/ngx_http_request.c 2012-03-05 20:49:32.000000000 +0800
> +++ nginx-1.0.15-patched/src/http/ngx_http_request.c 2012-05-11
> 20:50:01.478111234 +0800
> @@ -1900,6 +1900,7 @@
>
> if (rc == NGX_OK && r->filter_finalize) {
> c->error = 1;
> + ngx_http_finalize_connection(r);
> return;
> }
While the patch looks ok for me, the whole filter_finalize thing
is at best fragile (and known to cause at least one segfault as of
now). It really needs some attention (or even reimplementation).
Maxim Dounin
More information about the nginx-devel
mailing list