]> git.kaiwu.me - haproxy.git/commit
BUG/MEDIUM: stick-tables: update the bucket's next_exp before releasing its lock
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 19 Nov 2026 18:16:31 +0000 (19:16 +0100)
committerOlivier Houchard <cognet@ci0.org>
Fri, 20 Nov 2026 12:58:06 +0000 (13:58 +0100)
commit1318dfef8c51093c30a20ece107042056ca084bb
treee800aa95538bbce4b174e21dbb44d85f54d69acb
parent1810cc8fbf7975d1bf434ba079fbc07e74179f65
BUG/MEDIUM: stick-tables: update the bucket's next_exp before releasing its lock

process_tables_expire() computes the next expiration date of a table's
bucket under the bucket's lock, but releases the lock (and frees the
expired entries) before replacing the bucket's next_exp with this date. In
this window, another thread may insert a new entry (under the bucket's
lock) and call stktable_requeue_exp() for it. If next_exp still holds the
old (past) date, stktable_requeue_exp() considers the table as already
queued early enough and does nothing. Then the expiration task replaces
next_exp with the later date it computed, possibly TICK_ETERNITY, and
repositions or removes the table from its tree accordingly. The new entry
then doesn't expire until some other activity on this table requeues it.
The window was widened by commit 3e25104a9 ("MEDIUM: stick-tables: Avoid
freeing elements while holding a lock") which moved the freeing of expired
entries there.

Let's set next_exp before releasing the bucket's lock, so that any
insertion performed after it sees the new value. Since entries are
inserted under this lock, the computed date covers every entry present
in the bucket, so a concurrent stktable_requeue_exp() may safely be
overwritten and a plain store is enough, the CAS is not needed anymore.

This was introduced in 3.3 by commit 8bc8a21b2 ("MEDIUM: stick-tables: Use
a per-shard expiration task") and must be backported to 3.3.
src/stick_table.c