]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: leastconn: don't hide an avoided server from later lookups
authorOlivier Houchard <ohouchard@haproxy.com>
Tue, 1 Dec 2026 10:15:30 +0000 (11:15 +0100)
committerOlivier Houchard <cognet@ci0.org>
Tue, 1 Dec 2026 10:03:59 +0000 (11:03 +0100)
When fwlc_get_next_server() walks past a node without picking a server
from it, it raises the smallest key recorded in lbprm.lb_seq so that the
next lookups start further. It also does so after skipping the server to
avoid on a redispatch, though this server remains usable for everybody
else. The server then stays out of the lookups until another one is
queued at a key at or below its own: it gets no traffic while being the
least loaded, and if the other servers leave, requests are queued and
end with a 503 while a server is up.

Fix it by no longer raising the smallest key once a server was avoided
in the lookup. It can be reproduced with two servers, "retry-on 503" and
"option redispatch": hold a few requests on one server and have the
other one return a 503, the next requests all go to the busy server.

This was introduced by commit 9fe72bba3 ("MAJOR: leastconn; Revamp the
way servers are ordered.") in 3.2-dev9. This must be backported as far
as 3.2.

src/lb_fwlc.c

index e340fbaa7eccb8401732289aef84c6831cae9b26..ee876e21f1992fdccb963340fdeccf10b5944d8c 100644 (file)
@@ -848,7 +848,7 @@ redo:
                         * If we have a bigger element than the smallest recorded, and we're up to date,
                         * update the smallest one.
                         */
-                       if (likely(newcurseq == curseq && FWLC_LBPRM_SMALLEST(newcurseq) < node->key)) {
+                       if (likely(!avoided && newcurseq == curseq && FWLC_LBPRM_SMALLEST(newcurseq) < node->key)) {
                                if (fwlc_set_seq_and_smallest(&p->lbprm, curseq, FWLC_LBPRM_SEQ(curseq), node->key) != 0) {
                                        curseq = FWLC_LBPRM_SEQ(curseq) | ((uint64_t)node->key << 32);
                                        __ha_barrier_store();