Bladeren bron

fixing hard crash in case of client disconnection, take 2

tags/v0.4
Brice Figureau 18 jaren geleden
bovenliggende
commit
e5a7ca93e7
1 gewijzigde bestanden met toevoegingen van 17 en 19 verwijderingen
  1. 17
    19
      ngx_http_uploadprogress_module.c

+ 17
- 19
ngx_http_uploadprogress_module.c Bestand weergeven

@@ -265,54 +265,52 @@ ngx_http_uploadprogress_content_handler(ngx_http_request_t *r)
265 265
     /* call the original request handler */
266 266
     rc = upcf->handler(r);
267 267
 
268
-    /* hijack the read_event_handler */
268
+    /* bail out if error */
269
+		if (rc >= NGX_HTTP_SPECIAL_RESPONSE)
270
+			return rc;
271
+		
272
+		/* request is OK, hijack the read_event_handler */
269 273
     upcf->read_event_handler = r->read_event_handler;
270 274
     r->read_event_handler = ngx_http_uploadprogress_event_handler;
271
-
272 275
     return rc;
273 276
 }
274 277
 
275 278
 static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
276 279
 {
277
-  ngx_int_t  rc;
278 280
     ngx_str_t                       *id;
279 281
     ngx_slab_pool_t                 *shpool;
282
+    ngx_connection_t                *c;
280 283
     ngx_http_uploadprogress_ctx_t   *ctx;
281 284
     ngx_http_uploadprogress_node_t  *up;
282 285
     ngx_http_uploadprogress_conf_t  *upcf;
283 286
 
284 287
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_event_handler");
285 288
     
289
+		c = r->connection;
290
+		
286 291
     /* call the original read event handler */
287 292
     upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
288
- 
289
-    if (r->connection->read->timedout) {
290
-        r->connection->timedout = 1;
291
-        ngx_http_finalize_request(r, NGX_HTTP_REQUEST_TIME_OUT);
292
-        return;
293
-    }
293
+    upcf->read_event_handler(r);
294 294
 
295
-    rc = ngx_http_do_read_client_request_body(r);
296
-
297
-    if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
298
-        ngx_http_finalize_request(r, rc);
299
-				return;
300
-    }
295
+		/* check that the request/connection is still OK */
296
+		if (r->headers_out.status >= NGX_HTTP_SPECIAL_RESPONSE) {
297
+			return;
298
+		}
301 299
 
302 300
     /* find node, update rest */
303 301
     id = get_tracking_id(r);
304 302
 
305 303
     if (id == NULL) {
306
-        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
304
+        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
307 305
                        "upload-progress: read_event_handler cant find id");
308 306
         return;
309 307
     }
310 308
 
311
-    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
309
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
312 310
                    "upload-progress: read_event_handler found id: %V", id);
313 311
 
314 312
     if (upcf->shm_zone == NULL) {
315
-        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
313
+        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
316 314
                        "upload-progress: read_event_handler no shm_zone for id: %V", id);
317 315
         return;
318 316
     }
@@ -325,7 +323,7 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
325 323
     ngx_shmtx_lock(&shpool->mutex);
326 324
 
327 325
     up = find_node(id, ctx, r->connection->log);
328
-    if (up != NULL) {
326
+    if (up != NULL && !up->done) {
329 327
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
330 328
                        "upload-progress: read_event_handler found node: %V", id);
331 329
 				up->rest = r->request_body->rest;

Laden…
Annuleren
Opslaan