Skip to content

Commit

Permalink
Reuse of connections in lingering close.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mdounin committed Feb 11, 2021
1 parent 327e21c commit fb2a215
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/http/ngx_http_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -3437,6 +3437,9 @@ ngx_http_set_lingering_close(ngx_connection_t *c)
return;
}

c->close = 0;
ngx_reusable_connection(c, 1);

ngx_add_timer(rev, clcf->lingering_timeout);

if (rev->ready) {
Expand All @@ -3461,7 +3464,7 @@ ngx_http_lingering_close_handler(ngx_event_t *rev)
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http lingering close handler");

if (rev->timedout) {
if (rev->timedout || c->close) {
ngx_http_close_request(r, 0);
return;
}
Expand Down
5 changes: 4 additions & 1 deletion src/http/v2/ngx_http_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,9 @@ ngx_http_v2_lingering_close(ngx_connection_t *c)
return;
}

c->close = 0;
ngx_reusable_connection(c, 1);

ngx_add_timer(rev, clcf->lingering_timeout);

if (rev->ready) {
Expand All @@ -791,7 +794,7 @@ ngx_http_v2_lingering_close_handler(ngx_event_t *rev)
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http2 lingering close handler");

if (rev->timedout) {
if (rev->timedout || c->close) {
ngx_http_close_connection(c);
return;
}
Expand Down

0 comments on commit fb2a215

Please sign in to comment.