From ee90e8e380190468a87ab5df3597dafd4f5def53 Mon Sep 17 00:00:00 2001 From: Luke Gruber Date: Thu, 9 Apr 2026 14:35:57 -0400 Subject: Concurrent set fix when encountering garbage obj in find_or_insert When CASing the garbage key to EMPTY, if we succeed we should decrease set->size because we're trying to re-insert into the same slot right after. The insertion increases set->size if it succeeds. This issue can lead to set->size being overcounted, which can lead to more table resizes. --- concurrent_set.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/concurrent_set.c b/concurrent_set.c index c8b0c73881..42a5bfe8da 100644 --- a/concurrent_set.c +++ b/concurrent_set.c @@ -399,7 +399,12 @@ start_search: if (continuation) { goto probe_next; } - rbimpl_atomic_value_cas(&entry->key, curr_key, CONCURRENT_SET_EMPTY, RBIMPL_ATOMIC_RELEASE, RBIMPL_ATOMIC_RELAXED); + { + VALUE prev = rbimpl_atomic_value_cas(&entry->key, curr_key, CONCURRENT_SET_EMPTY, RBIMPL_ATOMIC_RELEASE, RBIMPL_ATOMIC_RELAXED); + if (prev == curr_key) { + rbimpl_atomic_sub(&set->size, 1, RBIMPL_ATOMIC_RELAXED); + } + } continue; } -- cgit v1.2.3