]> git.kaiwu.me - nginx.git/commitdiff
Upstream: fixed u->conf->preserve_output (ticket #1519).
authorMaxim Dounin <mdounin@mdounin.ru>
Thu, 5 Apr 2018 13:56:12 +0000 (16:56 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Thu, 5 Apr 2018 13:56:12 +0000 (16:56 +0300)
Previously, ngx_http_upstream_process_header() might be called after
we've finished reading response headers and switched to a different read
event handler, leading to errors with gRPC proxying.  Additionally,
the u->conf->read_timeout timer might be re-armed during reading response
headers (while this is expected to be a single timeout on reading
the whole response header).

src/http/ngx_http_upstream.c

index a415f58e3443e9aa0f963b215e2a1dfe02593ac7..8fc3042e7eff2b9d18a302e7fd96891f5584b03f 100644 (file)
@@ -2013,8 +2013,6 @@ ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u,
 
     /* rc == NGX_OK */
 
-    u->request_body_sent = 1;
-
     if (c->write->timer_set) {
         ngx_del_timer(c->write);
     }
@@ -2041,11 +2039,19 @@ ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u,
         return;
     }
 
-    ngx_add_timer(c->read, u->conf->read_timeout);
+    if (!u->request_body_sent) {
+        u->request_body_sent = 1;
 
-    if (c->read->ready) {
-        ngx_http_upstream_process_header(r, u);
-        return;
+        if (u->header_sent) {
+            return;
+        }
+
+        ngx_add_timer(c->read, u->conf->read_timeout);
+
+        if (c->read->ready) {
+            ngx_http_upstream_process_header(r, u);
+            return;
+        }
     }
 }