]> git.kaiwu.me - nginx.git/commitdiff
Merging r4195, r4196:
authorIgor Sysoev <igor@sysoev.ru>
Tue, 1 Nov 2011 14:13:25 +0000 (14:13 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Tue, 1 Nov 2011 14:13:25 +0000 (14:13 +0000)
AIO related fixes:

*) Fix for connection drops with AIO.

   Connections serving content with AIO to fast clients were dropped with
   "client timed out" messages after send_timeout from response start.

*) Fix for socket leak with "aio sendfile" and "limit_rate".

   Second aio post happened when timer set by limit_rate expired while we have
   aio request in flight, resulting in "second aio post" alert and socket leak.

   The patch adds actual protection from aio calls with r->aio already set to
   aio sendfile code in ngx_http_copy_filter().  This should fix other cases
   as well, e.g. when sending buffered to disk upstream replies while still
   talking to upstream.

   The ngx_http_writer() is also fixed to handle the above case (though it's
   mostly optimization now).

src/http/ngx_http_copy_filter_module.c
src/http/ngx_http_request.c

index 2eb6487d81b2b162a87b5c6effa75459eb59704d..0f9917e2e8d4323a75e6cfceaa28f9d06735e67b 100644 (file)
@@ -158,6 +158,11 @@ ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
             ngx_file_t            *file;
             ngx_http_ephemeral_t  *e;
 
+            if (r->aio) {
+                c->busy_sendfile = NULL;
+                return rc;
+            }
+
             file = c->busy_sendfile->file;
             offset = c->busy_sendfile->file_pos;
 
index ac54b1f5ad85e129bca87321bbcf93d7e285ae16..c0d56ecaaf67522e9cb0e38169701615471d46ca 100644 (file)
@@ -2248,17 +2248,17 @@ ngx_http_writer(ngx_http_request_t *r)
             return;
         }
 
-    } else {
-        if (wev->delayed || r->aio) {
-            ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0,
-                           "http writer delayed");
+    }
 
-            if (ngx_handle_write_event(wev, clcf->send_lowat) != NGX_OK) {
-                ngx_http_close_request(r, 0);
-            }
+    if (wev->delayed || r->aio) {
+        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0,
+                       "http writer delayed");
 
-            return;
+        if (ngx_handle_write_event(wev, clcf->send_lowat) != NGX_OK) {
+            ngx_http_close_request(r, 0);
         }
+
+        return;
     }
 
     rc = ngx_http_output_filter(r, NULL);
@@ -2274,7 +2274,7 @@ ngx_http_writer(ngx_http_request_t *r)
 
     if (r->buffered || r->postponed || (r == r->main && c->buffered)) {
 
-        if (!wev->ready && !wev->delayed) {
+        if (!wev->delayed) {
             ngx_add_timer(wev, clcf->send_timeout);
         }