From: Frederic Lecaille Date: Fri, 23 Oct 2026 09:46:36 +0000 (+0200) Subject: BUG/MINOR: peers: account incoming sessions in the per-thread applet counters X-Git-Tag: v3.5-dev10~46 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=2f60e4335310617e53ebf28578b25291d7c78809;p=haproxy.git BUG/MINOR: peers: account incoming sessions in the per-thread applet counters The per-thread applet counters of a peers section are used to pick the least loaded thread when creating an outgoing peer session. They are incremented in peer_session_create() for outgoing sessions only, but decremented in __peer_session_deinit() for all sessions, including incoming ones. Each incoming session thus makes the counter of its thread drift towards negative values, and outgoing sessions then tend to be created on the threads which handled incoming ones, defeating the load balancing. Must be backported as far as 3.0. --- diff --git a/src/peers.c b/src/peers.c index 8da94578c..f22f1599e 100644 --- a/src/peers.c +++ b/src/peers.c @@ -3166,6 +3166,11 @@ switchstate: curpeer->flags |= PEER_F_ALIVE; appctx->svcctx = curpeer; appctx->st0 = PEER_SESS_ST_SENDSUCCESS; + /* peer_session_create() accounts outgoing sessions, + * while __peer_session_deinit() releases the counter + * for every session, so account this incoming one too. + */ + HA_ATOMIC_INC(&curpeer->peers->applet_count[tid]); _HA_ATOMIC_INC(&active_peers); } __fallthrough;