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.
This commit is contained in:
Willy Tarreau 2025-09-09 17:44:46 +02:00
parent a771b14541
commit d5e7fba5c0

View File

@ -809,9 +809,12 @@ static struct task *stktable_add_pend_updates(struct task *t, void *ctx, unsigne
{ {
struct stktable *table = ctx; struct stktable *table = ctx;
struct eb32_node *eb; 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++) { 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); 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); HA_RWLOCK_WRUNLOCK(STK_TABLE_UPDT_LOCK, &table->updt_lock);
leave:
/* There's more to do, let's schedule another session */ /* There's more to do, let's schedule another session */
if (empty_tgid < global.nbtgroups) if (empty_tgid < global.nbtgroups)
tasklet_wakeup(table->updt_task); tasklet_wakeup(table->updt_task);