From: Olivier Houchard Date: Mon, 16 Nov 2026 16:27:00 +0000 (+0100) Subject: BUG/MEDIUM: stick-tables: compute the shard of string keys on the stored key X-Git-Url: https://git.kaiwu.me/http/$%7BISSUES%7D/static/gitweb.js?a=commitdiff_plain;ds=sidebyside;p=haproxy.git BUG/MEDIUM: stick-tables: compute the shard of string keys on the stored key stksess_setkey_shard() hashes string keys on the raw sample length, while the stored key is truncated to the table's "len" and stops at the first NUL. Peers send and hash the stored key, so for longer keys the creating node and its peers disagree on the shard, and entries are pushed to the wrong peers. Let's compute the shard on the stored key length. This was introduced in 2.7 by commit 36d156564 ("MINOR: peers: Support for peer shards") and should be backported to all stable versions. --- diff --git a/src/stick_table.c b/src/stick_table.c index af05bd4a0..dd8ee3504 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -250,8 +250,13 @@ static void stksess_setkey_shard(struct stktable *t, struct stksess *ts, { size_t keylen; - if (t->type == SMP_T_STR) - keylen = key->key_len; + if (t->type == SMP_T_STR) { + /* must match the stored key, which is truncated and stops at + * the first NUL, since it's what peers will use. + */ + keylen = key->key_len + 1 < t->key_size ? key->key_len : t->key_size - 1; + keylen = strnlen2(key->key, keylen); + } else keylen = t->key_size;