Browse Source

fix #36 - nginx reduces rquest_body->rest only on buffer recycling

Since nginx 1.3.9, the request body handler is able to decode chunked
encoding. This feature changed the behavior of the request body handler,
whereas before the request_body->rest was decremented on each call to
recv and the upload progress module was showing the correct rest
decrement. Now, request_body->rest is only decremented when the incoming
body buffer is reused. If this buffer is large (it's size depends on
client_body_buffer_size), then it can never be reused, thus the rest
field is never decremented until the end of the file.

This hasn't been detected and reproduced before, because I happen to
run the tests with small client_body_buffer_size (ie less than 10% from
the file uploaded).

The solution is to never use rest, but compute the correct rest by
tracking the current buffer size.

Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
tags/v0.9.1
Brice Figureau 12 years ago
parent
commit
39e4d53987
1 changed files with 12 additions and 1 deletions
  1. 12
    1
      ngx_http_uploadprogress_module.c

+ 12
- 1
ngx_http_uploadprogress_module.c View File

462
     ngx_http_uploadprogress_node_t              *up;
462
     ngx_http_uploadprogress_node_t              *up;
463
     ngx_http_uploadprogress_conf_t              *upcf;
463
     ngx_http_uploadprogress_conf_t              *upcf;
464
     ngx_http_uploadprogress_module_ctx_t        *module_ctx;
464
     ngx_http_uploadprogress_module_ctx_t        *module_ctx;
465
+    size_t                                       size;
466
+    off_t                                        rest;
467
+    
465
 
468
 
466
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_event_handler");
469
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_event_handler");
467
     
470
     
517
     if (up != NULL && !up->done) {
520
     if (up != NULL && !up->done) {
518
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
521
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
519
                        "upload-progress: read_event_handler found node: %V", id);
522
                        "upload-progress: read_event_handler found node: %V", id);
520
-        up->rest = r->request_body->rest;
523
+        rest = r->request_body->rest;
524
+        size = r->request_body->buf->last - r->request_body->buf->pos;
525
+        if ((off_t) size < rest) {
526
+            rest -= size;
527
+        } else {
528
+            rest = 0;
529
+        }
530
+        
531
+        up->rest = rest;
521
         if(up->length == 0)
532
         if(up->length == 0)
522
             up->length = r->headers_in.content_length_n;
533
             up->length = r->headers_in.content_length_n;
523
         ngx_log_debug3(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
534
         ngx_log_debug3(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,

Loading…
Cancel
Save