[PATCH 07 of 13] Request body: properly handle events while discarding body

Maxim Dounin mdounin at mdounin.ru
Fri Nov 16 11:02:29 UTC 2012


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1353062357 -14400
# Node ID cc692c8a60ad93fa9092140d601d57bd38764ff0
# Parent  49ecf88ba2e6bf559f5cc307e466b3284555ae09
Request body: properly handle events while discarding body.

An attempt to call ngx_handle_read_event() before actually reading
data from a socket might result in read event being disabled, which is
wrong.  Catched by body.t test on Solaris.

diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c
--- a/src/http/ngx_http_request_body.c
+++ b/src/http/ngx_http_request_body.c
@@ -482,19 +482,21 @@ ngx_http_discard_request_body(ngx_http_r
         }
     }
 
+    if (ngx_http_read_discarded_request_body(r) == NGX_OK) {
+        r->lingering_close = 0;
+        return NGX_OK;
+    }
+
+    /* == NGX_AGAIN */
+
     r->read_event_handler = ngx_http_discarded_request_body_handler;
 
     if (ngx_handle_read_event(rev, 0) != NGX_OK) {
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
-    if (ngx_http_read_discarded_request_body(r) == NGX_OK) {
-        r->lingering_close = 0;
-
-    } else {
-        r->count++;
-        r->discard_body = 1;
-    }
+    r->count++;
+    r->discard_body = 1;
 
     return NGX_OK;
 }



More information about the nginx-devel mailing list