From 7e7b0d2a3486fb9bd2e46a3a3c05f642b02d5436 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Mon, 16 Nov 2026 17:27:00 +0100 Subject: [PATCH] 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. --- src/stick_table.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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; -- 2.47.3