]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: stick-tables: compute the shard of string keys on the stored key master
authorOlivier Houchard <ohouchard@haproxy.com>
Mon, 16 Nov 2026 16:27:00 +0000 (17:27 +0100)
committerOlivier Houchard <cognet@ci0.org>
Mon, 16 Nov 2026 16:13:04 +0000 (17:13 +0100)
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.

src/stick_table.c

index af05bd4a00d273a17e1b00e0127db5553f4ea134..dd8ee3504a4ad01bb35154371b1f0bc052477fb1 100644 (file)
@@ -250,8 +250,13 @@ static void stksess_setkey_shard(struct stktable *t, struct stksess *ts,
 {
        size_t keylen;
 
 {
        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;
 
        else
                keylen = t->key_size;