]> git.kaiwu.me - nginx.git/commitdiff
Fixed "zero size buf in output" alerts.
authorMaxim Dounin <mdounin@mdounin.ru>
Fri, 3 Jan 2014 23:32:22 +0000 (03:32 +0400)
committerMaxim Dounin <mdounin@mdounin.ru>
Fri, 3 Jan 2014 23:32:22 +0000 (03:32 +0400)
If a request had an empty request body (with Content-Length: 0), and there
were preread data available (e.g., due to a pipelined request in the buffer),
the "zero size buf in output" alert might be logged while proxying the
request to an upstream.

Similar alerts appeared with client_body_in_file_only if a request had an
empty request body.

src/http/ngx_http_request_body.c

index 97df69c0588e7d0564eea276276b99319e2ce6bc..94cdbeed63fe48c31b19b65a14f089658666c8d3 100644 (file)
@@ -150,21 +150,27 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
                 goto done;
             }
 
-            cl = ngx_chain_get_free_buf(r->pool, &rb->free);
-            if (cl == NULL) {
-                rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
-                goto done;
-            }
+            if (rb->temp_file->file.offset != 0) {
 
-            b = cl->buf;
+                cl = ngx_chain_get_free_buf(r->pool, &rb->free);
+                if (cl == NULL) {
+                    rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
+                    goto done;
+                }
 
-            ngx_memzero(b, sizeof(ngx_buf_t));
+                b = cl->buf;
 
-            b->in_file = 1;
-            b->file_last = rb->temp_file->file.offset;
-            b->file = &rb->temp_file->file;
+                ngx_memzero(b, sizeof(ngx_buf_t));
 
-            rb->bufs = cl;
+                b->in_file = 1;
+                b->file_last = rb->temp_file->file.offset;
+                b->file = &rb->temp_file->file;
+
+                rb->bufs = cl;
+
+            } else {
+                rb->bufs = NULL;
+            }
         }
 
         post_handler(r);
@@ -375,20 +381,26 @@ ngx_http_do_read_client_request_body(ngx_http_request_t *r)
             return NGX_HTTP_INTERNAL_SERVER_ERROR;
         }
 
-        cl = ngx_chain_get_free_buf(r->pool, &rb->free);
-        if (cl == NULL) {
-            return NGX_HTTP_INTERNAL_SERVER_ERROR;
-        }
+        if (rb->temp_file->file.offset != 0) {
 
-        b = cl->buf;
+            cl = ngx_chain_get_free_buf(r->pool, &rb->free);
+            if (cl == NULL) {
+                return NGX_HTTP_INTERNAL_SERVER_ERROR;
+            }
 
-        ngx_memzero(b, sizeof(ngx_buf_t));
+            b = cl->buf;
+
+            ngx_memzero(b, sizeof(ngx_buf_t));
+
+            b->in_file = 1;
+            b->file_last = rb->temp_file->file.offset;
+            b->file = &rb->temp_file->file;
 
-        b->in_file = 1;
-        b->file_last = rb->temp_file->file.offset;
-        b->file = &rb->temp_file->file;
+            rb->bufs = cl;
 
-        rb->bufs = cl;
+        } else {
+            rb->bufs = NULL;
+        }
     }
 
     r->read_event_handler = ngx_http_block_reading;
@@ -843,6 +855,10 @@ ngx_http_request_body_length_filter(ngx_http_request_t *r, ngx_chain_t *in)
 
     for (cl = in; cl; cl = cl->next) {
 
+        if (rb->rest == 0) {
+            break;
+        }
+
         tl = ngx_chain_get_free_buf(r->pool, &rb->free);
         if (tl == NULL) {
             return NGX_HTTP_INTERNAL_SERVER_ERROR;