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

agentzh agentzh at gmail.com
Sat May 12 15:10:09 UTC 2012


Hello!

On Sat, May 12, 2012 at 8:47 PM, Maxim Dounin <mdounin at mdounin.ru> wrote:
>
> I assume you use error_page to redirect 412, right?  You may want
> to show config (and more complete debug log) to simplify reading.
>

Nope. There is no error_page directive in my nginx.conf. Here is the
configure file I'm using:

https://gist.github.com/2667007

The request I'm using is this:

GET / HTTP/1.1
Host: localhost
Connection: Close
If-Unmodified-Since: Thu, 10 May 2012 07:50:47 GMT

The debug log is here (only the first part is given, because the whole
is too huge):

https://gist.github.com/2666809

>>       2 2012/05/12 20:14:01 [debug] 2770#0: *1 http finalize request:
>> -4, "/index.html?" a:1, c:2
>
> How this happens to be -4 (NGX_DONE)?

In short, the ngx_http_finalize_request(r, NGX_DONE) call was caused
by recursive calling of ngx_http_core_content_phase due to the
standard ngx_index module.

To be more specific, the backtrace for the (first)
ngx_http_finalize_request(r, NGX_AGAIN) call looks like this

#0  ngx_http_finalize_request (r=0x77ccb0, rc=-2) at
src/http/ngx_http_request.c:1890
#1  0x0000000000455758 in ngx_http_core_content_phase (r=0x77ccb0, ph=0x78d5c8)
    at src/http/ngx_http_core_module.c:1377
#2  0x00000000004542a4 in ngx_http_core_run_phases (r=0x77ccb0)
    at src/http/ngx_http_core_module.c:862
#3  0x000000000045421b in ngx_http_handler (r=0x77ccb0) at
src/http/ngx_http_core_module.c:845
#4  0x0000000000457d53 in ngx_http_internal_redirect (r=0x77ccb0,
uri=0x7fffe0aadc40, args=0x77cfd0)
    at src/http/ngx_http_core_module.c:2516
#5  0x0000000000482b8b in ngx_http_index_handler (r=0x77ccb0)
    at src/http/modules/ngx_http_index_module.c:265
#6  0x000000000045573a in ngx_http_core_content_phase (r=0x77ccb0, ph=0x78d598)
    at src/http/ngx_http_core_module.c:1374
#7  0x00000000004542a4 in ngx_http_core_run_phases (r=0x77ccb0)
    at src/http/ngx_http_core_module.c:862
#8  0x000000000045421b in ngx_http_handler (r=0x77ccb0) at
src/http/ngx_http_core_module.c:845
[...]

We can see that when ngx_http_finalize_request (r=0x77ccb0, rc=-2)
returns, the ngx_http_internal_redirect call at frame #4 will then
return NGX_DONE to ngx_http_index_handler at frame #5, and in turn,
ngx_http_index_handler will also return NGX_DONE to
ngx_http_core_content_phase at frame #6, and finally triggering the
call ngx_http_finalize_request(r, NGX_DONE).

If you have further questions, please let me know :) And thank you
very much for looking into this!

Best regards,
-agentzh



More information about the nginx-devel mailing list