[nginx] Upstream keepalive: resuming now ignores ready connections.
Maxim Dounin
mdounin at mdounin.ru
Fri Aug 28 12:23:27 UTC 2026
details: http://freenginx.org/hg/nginx/rev/a3cb9a16e4e8
branches:
changeset: 9587:a3cb9a16e4e8
user: Maxim Dounin <mdounin at mdounin.ru>
date: Fri Aug 28 15:14:47 2026 +0300
description:
Upstream keepalive: resuming now ignores ready connections.
In ngx_http_upstream_get_keepalive_peer(), c->read->ready flag might be
set only if the upstream connection was reported readable in this event
loop iteration (and the close handler wasn't called yet). Now such
connections are ignored, so the close handler will close them once
called.
This slightly reduces the race window between closing a connection by
the backend and using the connection to send a request at the same time.
diffstat:
src/http/modules/ngx_http_upstream_keepalive_module.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diffs (14 lines):
diff --git a/src/http/modules/ngx_http_upstream_keepalive_module.c b/src/http/modules/ngx_http_upstream_keepalive_module.c
--- a/src/http/modules/ngx_http_upstream_keepalive_module.c
+++ b/src/http/modules/ngx_http_upstream_keepalive_module.c
@@ -264,6 +264,10 @@ ngx_http_upstream_get_keepalive_peer(ngx
item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue);
c = item->connection;
+ if (c->read->ready) {
+ continue;
+ }
+
if (ngx_memn2cmp((u_char *) &item->sockaddr, (u_char *) pc->sockaddr,
item->socklen, pc->socklen)
== 0)
More information about the nginx-devel
mailing list