Mercurial > hg > nginx
changeset 8125:cffaf3f2eec8
Lingering close for connections with pipelined requests.
This is expected to help with clients using pipelining with some constant
depth, such as apt[1][2].
When downloading many resources, apt uses pipelining with some constant
depth, a number of requests in flight. This essentially means that after
receiving a response it sends an additional request to the server, and
this can result in requests arriving to the server at any time. Further,
additional requests are sent one-by-one, and can be easily seen as such
(neither as pipelined, nor followed by pipelined requests).
The only safe approach to close such connections (for example, when
keepalive_requests is reached) is with lingering. To do so, now nginx
monitors if pipelining was used on the connection, and if it was, closes
the connection with lingering.
[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=973861#10
[2] https://mailman.nginx.org/pipermail/nginx-devel/2023-January/ZA2SP5SJU55LHEBCJMFDB2AZVELRLTHI.html
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 02 Feb 2023 23:38:48 +0300 |
parents | f5515e727656 |
children | 9bcc5cc94ff4 |
files | src/core/ngx_connection.h src/http/ngx_http_request.c |
diffstat | 2 files changed, 4 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/core/ngx_connection.h Sat Jan 28 05:23:33 2023 +0300 +++ b/src/core/ngx_connection.h Thu Feb 02 23:38:48 2023 +0300 @@ -172,6 +172,7 @@ unsigned timedout:1; unsigned error:1; unsigned destroyed:1; + unsigned pipeline:1; unsigned idle:1; unsigned reusable:1;
--- a/src/http/ngx_http_request.c Sat Jan 28 05:23:33 2023 +0300 +++ b/src/http/ngx_http_request.c Thu Feb 02 23:38:48 2023 +0300 @@ -2753,7 +2753,8 @@ || (clcf->lingering_close == NGX_HTTP_LINGERING_ON && (r->lingering_close || r->header_in->pos < r->header_in->last - || r->connection->read->ready))) + || r->connection->read->ready + || r->connection->pipeline))) { ngx_http_set_lingering_close(r->connection); return; @@ -3123,6 +3124,7 @@ c->sent = 0; c->destroyed = 0; + c->pipeline = 1; if (rev->timer_set) { ngx_del_timer(rev);