]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stick-tables: don't wait indefinitely in stktable_add_pend_updates()
authorWilly Tarreau <w@1wt.eu>
Tue, 9 Sep 2025 15:44:46 +0000 (17:44 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 9 Sep 2025 15:56:37 +0000 (17:56 +0200)
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

index 90fc7b0e67fb8fa457fc4a1569e72746e1b5dd75..cb70d16c2c562f32bec353774da0e57446e62ea6 100644 (file)
@@ -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);