Skip to content

Commit 4f3559b

Browse files
committed
docs: Fix misleading race-safety comment in RequestCoalescer
The comment claimed GetOrAdd would replace the entry (preventing the race), but ConcurrentDictionary.GetOrAdd returns the existing entry. The race can cause a missed coalescing opportunity but is benign — both requests produce valid results independently.
1 parent d5fe847 commit 4f3559b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Imazen.Caching/RequestCoalescer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ private sealed class CoalescingEntry
7878
{
7979
if (Interlocked.Decrement(ref entry.WaiterCount) == 0)
8080
{
81-
// Last waiter cleans up. Race-safe: if another thread just incremented,
82-
// TryRemove will fail because GetOrAdd already replaced the entry.
81+
// Last waiter cleans up. There's a narrow race where a new thread
82+
// could GetOrAdd the same entry between our decrement and TryRemove,
83+
// causing a missed coalescing opportunity. This is benign — both
84+
// requests produce valid results, just without sharing the factory call.
8385
_entries.TryRemove(key, out _);
8486
}
8587
}

0 commit comments

Comments
 (0)