comparison src/http/ngx_http_request.c @ 7766:3e83336cda5b

Reuse of connections in lingering close. This is particularly important in HTTP/2, where keepalive connections are closed with lingering. Before the patch, reusing a keepalive HTTP/2 connection resulted in the connection waiting for lingering close to remain in the reusable connections queue, preventing ngx_drain_connections() from closing additional connections. The patch fixes it by marking the connection reusable again, and so moving it in the reusable connections queue. Further, it makes actually possible to reuse such connections if needed.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 11 Feb 2021 21:52:09 +0300
parents 4e141d0816d4
children 4a9d28f8f39e 13f7085b90d2
comparison
equal deleted inserted replaced
7765:519b55453c45 7766:3e83336cda5b
3435 ngx_shutdown_socket_n " failed"); 3435 ngx_shutdown_socket_n " failed");
3436 ngx_http_close_request(r, 0); 3436 ngx_http_close_request(r, 0);
3437 return; 3437 return;
3438 } 3438 }
3439 3439
3440 c->close = 0;
3441 ngx_reusable_connection(c, 1);
3442
3440 ngx_add_timer(rev, clcf->lingering_timeout); 3443 ngx_add_timer(rev, clcf->lingering_timeout);
3441 3444
3442 if (rev->ready) { 3445 if (rev->ready) {
3443 ngx_http_lingering_close_handler(rev); 3446 ngx_http_lingering_close_handler(rev);
3444 } 3447 }
3459 r = c->data; 3462 r = c->data;
3460 3463
3461 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, 3464 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
3462 "http lingering close handler"); 3465 "http lingering close handler");
3463 3466
3464 if (rev->timedout) { 3467 if (rev->timedout || c->close) {
3465 ngx_http_close_request(r, 0); 3468 ngx_http_close_request(r, 0);
3466 return; 3469 return;
3467 } 3470 }
3468 3471
3469 timer = (ngx_msec_t) r->lingering_time - (ngx_msec_t) ngx_time(); 3472 timer = (ngx_msec_t) r->lingering_time - (ngx_msec_t) ngx_time();