]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: peers: account incoming sessions in the per-thread applet counters
authorFrederic Lecaille <flecaille@haproxy.com>
Fri, 23 Oct 2026 09:46:36 +0000 (11:46 +0200)
committerFrederic Lecaille <flecaille@haproxy.com>
Mon, 26 Oct 2026 10:39:41 +0000 (11:39 +0100)
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

index 8da94578c804497837263306170a302a9e64c5f7..f22f1599e938ad99caba18a321c89c046eda97cc 100644 (file)
@@ -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;