]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: stick-tables: always respect the to_batch limit when trashing
authorWilly Tarreau <w@1wt.eu>
Fri, 12 Apr 2024 08:02:26 +0000 (10:02 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 12 Apr 2024 15:58:54 +0000 (17:58 +0200)
When adding the shards support to tables with commit 1a088da7c ("MAJOR:
stktable: split the keys across multiple shards to reduce contention"),
the condition to stop eliminating entries based on the batch size being
reached is based on a pre-decrement of the max_search counter, but now
it goes back into the outer loop which doesn't check it, so next time
it does it when entering the next shard, it will become even more
negative and will properly stop, but at first glance it looks like an
int overflow (which it is not). Let's make sure the outer loop stops
on this condition so that we don't continue searching when the limit
is reached.

src/stick_table.c

index 0a0012978132bb306315b192233e9981855620e0..c007cda78058eddd981bcefe41d74829603b4dea 100644 (file)
@@ -336,6 +336,9 @@ int stktable_trash_oldest(struct stktable *t, int to_batch)
 
                HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock);
 
+               if (max_search <= 0)
+                       break;
+
                shard = (shard + 1) % CONFIG_HAP_TBL_BUCKETS;
                if (!shard)
                        break;