]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: lb-chash: bound the walk when the saved cursor changed tree
authorWilly Tarreau <w@1wt.eu>
Thu, 6 Aug 2026 07:31:15 +0000 (09:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 7 Aug 2026 13:03:57 +0000 (15:03 +0200)
commit23cf528c76cfbea9dbdf89cd9b885e0398884934
treef885c993dc7b04267385c494924a4085a1b700fe
parent30103ca7a233453d0dd857aa7db22e8cfcccedc8
BUG/MINOR: lb-chash: bound the walk when the saved cursor changed tree

chash.last is not reset when the tree in use switches from the backup
servers back to the active ones. The next call then starts walking the
active tree while keeping a backup node as the stop condition, which it can
never reach, so it cycles over the active tree forever as soon as no server
can be picked: all of them saturated (maxconn reached with a queue, or
served >= the dynamic maxconn), or the only one left being the server to
avoid on a redispatch. In this case, if chash.last (assigned to <stop>)
isn't in the current tree, the loop will run forever.

Let's just count the number of times we wrap and stop at the second,
which indicates that the stop server is not in the tree.

Note that this is more theoretical than practical: this needs
"hash-type consistent" with requests not carrying the hash key so that
this fallback is used at all, backup servers with "option allbackups"
(without it lbprm.fbck is returned directly and the backup tree is never
walked), and all active servers going down then one coming back while
the remaining ones are saturated. In practice it has been there since
consistent hash was introduced in 1.4 by commit 6b2e11be1 ("[MEDIUM]
backend: implement consistent hashing variation") and was never
reported. It may be backported to all stable versions.

Reported-by: Claude (ANT-2026-98TCHHRD)
src/lb_chash.c