Is there a bug in ngx_http_upstream_module's broken connection check code?

speedfirst nginx-forum at
Thu Jun 23 08:14:47 MSD 2011

In the function "ngx_http_upstream_check_broken_connection" of
ngx_http_upstream.c, there is a code segment like below:

 n = recv(c->fd, buf, 1, MSG_PEEK);
 else { /* n == 0 */
        err = 0;

Here use whether receiving 0 bytes from downstream client to judge
whether the connection has been closed. However, if the downstream
connection is https, and the connection is cosed, this n will never be
0. So the code fails to check the broken connection for https.

My test is create a connection by firefox and click the "Stop" button in
the firefox. If the connection is http, n will be 0; but if the
connection is https, n is always 1. I try to increase the peek read
limit from 1 to 1000 and then n will get 37.

So is it a bug or I misunderstand something?


Posted at Nginx Forum:,209276,209276#msg-209276

More information about the nginx mailing list