Welcome! Log In Create A New Profile

Advanced

[nginx] Reuse of connections in lingering close.

Maxim Dounin
February 11, 2021 02:58PM
details: https://hg.nginx.org/nginx/rev/3e83336cda5b
branches:
changeset: 7766:3e83336cda5b
user: Maxim Dounin <mdounin@mdounin.ru>
date: Thu Feb 11 21:52:09 2021 +0300
description:
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.

diffstat:

src/http/ngx_http_request.c | 5 ++++-
src/http/v2/ngx_http_v2.c | 5 ++++-
2 files changed, 8 insertions(+), 2 deletions(-)

diffs (44 lines):

diff -r 519b55453c45 -r 3e83336cda5b src/http/ngx_http_request.c
--- a/src/http/ngx_http_request.c Mon Feb 01 16:42:50 2021 +0300
+++ b/src/http/ngx_http_request.c Thu Feb 11 21:52:09 2021 +0300
@@ -3437,6 +3437,9 @@ ngx_http_set_lingering_close(ngx_connect
return;
}

+ c->close = 0;
+ ngx_reusable_connection(c, 1);
+
ngx_add_timer(rev, clcf->lingering_timeout);

if (rev->ready) {
@@ -3461,7 +3464,7 @@ ngx_http_lingering_close_handler(ngx_eve
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;
}
diff -r 519b55453c45 -r 3e83336cda5b src/http/v2/ngx_http_v2.c
--- a/src/http/v2/ngx_http_v2.c Mon Feb 01 16:42:50 2021 +0300
+++ b/src/http/v2/ngx_http_v2.c Thu Feb 11 21:52:09 2021 +0300
@@ -767,6 +767,9 @@ ngx_http_v2_lingering_close(ngx_connecti
return;
}

+ c->close = 0;
+ ngx_reusable_connection(c, 1);
+
ngx_add_timer(rev, clcf->lingering_timeout);

if (rev->ready) {
@@ -791,7 +794,7 @@ ngx_http_v2_lingering_close_handler(ngx_
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;
}
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Reuse of connections in lingering close.

Maxim Dounin 67 February 11, 2021 02:58PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 83
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready