From 2f60e4335310617e53ebf28578b25291d7c78809 Mon Sep 17 00:00:00 2001 From: Frederic Lecaille Date: Fri, 23 Oct 2026 11:46:36 +0200 Subject: [PATCH] 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. --- src/peers.c | 5 +++++ 1 file changed, 5 insertions(+) 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; -- 2.47.3