nginx-0.0.7-2004-07-07-10:15:04 import
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index 335d1da..e6f27a2 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -573,6 +573,8 @@
 
     p->action = "connecting to upstream";
 
+    p->request->connection->single_connection = 0;
+
     rc = ngx_event_connect_peer(&p->upstream->peer);
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0,
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index e2c2891..1857f59 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -290,6 +290,7 @@
         return;
     }
 
+    c->single_connection = 1;
     r->connection = c;
     r->pipeline = c->pipeline;
     r->header_in = c->buffer;
@@ -1760,9 +1761,11 @@
         c->read->closed = 1;
         c->write->closed = 1;
 
-        ngx_unlock(&c->lock);
-        c->read->locked = 0;
-        c->write->locked = 0;
+        if (c->single_connection) {
+            ngx_unlock(&c->lock);
+            c->read->locked = 0;
+            c->write->locked = 0;
+        }
 
         ngx_mutex_unlock(ngx_posted_events_mutex);
     }