[PATCH] nginx does not close the connection for 412 responses under extreme conditions

agentzh agentzh at gmail.com
Fri May 11 12:59:48 UTC 2012


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.

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;
     }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginx-1.0.15-filter_finalize_hang.patch
Type: application/octet-stream
Size: 331 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20120511/96f8429a/attachment.obj>


More information about the nginx-devel mailing list