]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MEDIUM: lb-chash: always properly initialize lb_nodes with dynamic servers
authorWilly Tarreau <w@1wt.eu>
Tue, 10 Feb 2026 06:10:09 +0000 (07:10 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 10 Feb 2026 06:22:54 +0000 (07:22 +0100)
commit64c5d45a269749a30a372420b4d196235dc8d745
treee67fda4290bcd40b565a1bd34385b481a8a76920
parent62239539bff7424e2548ac72d94fbf617dc4bee8
BUG/MEDIUM: lb-chash: always properly initialize lb_nodes with dynamic servers

An issue was introduced in 3.0 with commit faa8c3e024 ("MEDIUM: lb-chash:
Deterministic node hashes based on server address"): the new server_key
field and lb_nodes entries initialization were not updated for servers
added at run time with "add server": server_key remains zero and the key
used in lb_node remains the one depending only on the server's ID.

This will cause trouble when adding new servers with consistent hashing,
because the hash-key will be ignored until the server's weight changes
and the key difference is detected, leading to its recalculation.

This is essentially caused by the poorly placed lb_nodes initialization
that is specific to lb-chash and had to be replicated in the code dealing
with server addition.

This commit solves the problem by adding a new ->server_init() function
in the lbprm proxy struct, that is called by the server addition code.
This also allows to abandon the complex check for LB algos that was
placed there for that purpose. For now only lb-chash provides such a
function, and calls it as well during initial setup. This way newly
added servers always use the correct key now.

While it should also theoretically have had an impact on servers added
with the "random" algorithm, it's unlikely that the difference between
proper server keys and those based on their ID could have had any visible
effect.

This patch should be backported as far as 3.0. The backport may be eased
by a preliminary backport of previous commit "CLEANUP: lb-chash: free
lb_nodes from chash's deinit(), not global", though this is not strictly
necessary if context is manually adjusted.
include/haproxy/backend-t.h
src/lb_chash.c
src/server.c