upstream keepalive - call for testing

Maxim Dounin mdounin at mdounin.ru
Thu Sep 8 09:27:34 UTC 2011


Hello!

On Wed, Sep 07, 2011 at 04:33:38PM -0700, Matthieu Tourne wrote:

> Thanks for the all-included patch from 1.1.2
> 
> It seems that keepalive connections aren't working in combination with
> proxy_buffering off; (c->read->ready is set to 1)
> It worked before this last update, is this the intended behavior ?

Linux with epoll, right?  Please try the following patch:

diff --git a/src/http/modules/ngx_http_upstream_keepalive_module.c b/src/http/modules/ngx_http_upstream_keepalive_module.c
--- a/src/http/modules/ngx_http_upstream_keepalive_module.c
+++ b/src/http/modules/ngx_http_upstream_keepalive_module.c
@@ -321,7 +321,6 @@ ngx_http_upstream_free_keepalive_peer(ng
     if (kp->failed
         || c == NULL
         || c->read->eof
-        || c->read->ready
         || c->read->error
         || c->read->timedout
         || c->write->error
@@ -382,6 +381,10 @@ ngx_http_upstream_free_keepalive_peer(ng
     item->socklen = pc->socklen;
     ngx_memcpy(&item->sockaddr, pc->sockaddr, pc->socklen);

+    if (c->read->ready) {
+        ngx_http_upstream_keepalive_close_handler(c->read);
+    }
+
 invalid:

     kp->original_free_peer(pc, kp->data, state);
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -2142,7 +2142,7 @@ ngx_http_upstream_send_response(ngx_http
                 return;
             }

-            if (u->peer.connection->read->ready) {
+            if (u->peer.connection->read->ready || u->length == 0) {
                 ngx_http_upstream_process_non_buffered_upstream(r, u);
             }
         }

Second part fixes one more problem with handling of responses with 
empty body over keepalive connections, found during testing with 
various event methods.

Maxim Dounin



More information about the nginx mailing list