From: Olivier Houchard Date: Thu, 19 Mar 2020 22:52:28 +0000 (+0100) Subject: BUG/MEDIUM: connections: Don't forget to decrement idle connection counters. X-Git-Tag: v2.2-dev5~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fdc7ee21739bfbdc2585dd3977d4ab3cb9a7df14;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: connections: Don't forget to decrement idle connection counters. In conn_backend_get(), when we manage to get an idle connection from the current thread's pool, don't forget to decrement the idle connection counters, or we may end up not reusing connections when we could, and/or killing connections when we shouldn't. --- diff --git a/src/backend.c b/src/backend.c index 96d8d17ad8..8f81c61027 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1095,8 +1095,10 @@ static struct connection *conn_backend_get(struct server *srv, int is_safe) /* If we found a connection in our own list, and we don't have to * steal one from another thread, then we're done. */ - if (conn) - return conn; + if (conn) { + i = tid; + goto fix_conn; + } /* Lookup all other threads for an idle connection, starting from tid + 1 */ for (i = tid; !found && (i = ((i + 1 == global.nbthread) ? 0 : i + 1)) != tid;) { @@ -1116,6 +1118,7 @@ static struct connection *conn_backend_get(struct server *srv, int is_safe) if (!found) conn = NULL; else { +fix_conn: conn->idle_time = 0; _HA_ATOMIC_SUB(&srv->curr_idle_conns, 1); _HA_ATOMIC_SUB(&srv->curr_idle_thr[i], 1);