[nginx] Threads: fixed request hang with aio_write and subrequests.

Maxim Dounin mdounin at mdounin.ru
Tue Mar 28 16:25:28 UTC 2017


details:   http://hg.nginx.org/nginx/rev/4cb4ffe06785
branches:  
changeset: 6950:4cb4ffe06785
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Tue Mar 28 18:15:41 2017 +0300
description:
Threads: fixed request hang with aio_write and subrequests.

If the subrequest is already finalized, the handler set with aio_write
may still be used by sendfile in threads when using range requests
(see also e4c1f5b32868, and the original note in 9fd738b85fad).  Calling
already finalized subrequest's r->write_event_handler in practice
results in request hang in some cases.

Fix is to trigger connection event handler if the subrequest was already
finalized.

diffstat:

 src/http/ngx_http_upstream.c |  16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diffs (26 lines):

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
@@ -3736,9 +3736,19 @@ ngx_http_upstream_thread_event_handler(n
     r->main->blocked--;
     r->aio = 0;
 
-    r->write_event_handler(r);
-
-    ngx_http_run_posted_requests(c);
+    if (r->done) {
+        /*
+         * trigger connection event handler if the subrequest was
+         * already finalized; this can happen if the handler is used
+         * for sendfile() in threads
+         */
+
+        c->write->handler(c->write);
+
+    } else {
+        r->write_event_handler(r);
+        ngx_http_run_posted_requests(c);
+    }
 }
 
 #endif


More information about the nginx-devel mailing list