From d5e7fba5c035a5a2b5f1136be2d2de70d529b118 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 9 Sep 2025 17:44:46 +0200 Subject: [PATCH] MEDIUM: stick-tables: don't wait indefinitely in stktable_add_pend_updates() This one doesn't need to wait forever, if it cannot work it can postpone it. When building with a high value of STKTABLE_MAX_UPDATES_AT_ONCE (1000), it's still possible to trigger warnings in this function on the write lock that is contended by peers and expiration. Changing it for a trylock resolves the issue. This should be backported to 3.2 after a bit of testing. --- src/stick_table.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/stick_table.c b/src/stick_table.c index 90fc7b0e6..cb70d16c2 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -809,9 +809,12 @@ static struct task *stktable_add_pend_updates(struct task *t, void *ctx, unsigne { struct stktable *table = ctx; struct eb32_node *eb; - int i, is_local, cur_tgid = tgid - 1, empty_tgid = 0; + int i = 0, is_local, cur_tgid = tgid - 1, empty_tgid = 0; + + /* we really don't want to wait on this one */ + if (HA_RWLOCK_TRYWRLOCK(STK_TABLE_LOCK, &table->updt_lock) != 0) + goto leave; - HA_RWLOCK_WRLOCK(STK_TABLE_UPDT_LOCK, &table->updt_lock); for (i = 0; i < STKTABLE_MAX_UPDATES_AT_ONCE; i++) { struct stksess *stksess = MT_LIST_POP(&table->pend_updts[cur_tgid], typeof(stksess), pend_updts); @@ -854,6 +857,7 @@ static struct task *stktable_add_pend_updates(struct task *t, void *ctx, unsigne HA_RWLOCK_WRUNLOCK(STK_TABLE_UPDT_LOCK, &table->updt_lock); +leave: /* There's more to do, let's schedule another session */ if (empty_tgid < global.nbtgroups) tasklet_wakeup(table->updt_task);