Skip to content

Conversation

@dwisiswant0
Copy link
Member

fix(sync): AdaptiveWaitGroup counter racy

causing flaky tests.

Reorder counter updates relative to semaphore
ops to prevent race condition where Current()
could temporarily exceed $$size+1$$.

  • Add(): inc counter before acquiring semaphore
  • Done(): dec counter before releasing semaphore

This eliminates the race window where both Add()
and Done() had pending counter updates, causing
TestThrottling to fail in CI (#700) with Current()
reaching 6-7 instead of expected max. of 5
(size=4).

causing flaky tests.

Reorder counter updates relative to semaphore
ops to prevent race condition where `Current()`
could temporarily exceed 2485582size+12485582.

* `Add()`: inc counter before acquiring semaphore
* `Done()`: dec counter before releasing semaphore

This eliminates the race window where both `Add()`
and `Done()` had pending counter updates, causing
`TestThrottling` to fail in CI with `Current()`
reaching 6-7 instead of expected max. of 5
(size=4).

Signed-off-by: Dwi Siswanto <git@dw1.io>
@dwisiswant0
Copy link
Member Author

@coderabbitai create an issue for this.

@dwisiswant0 dwisiswant0 merged commit 5ef874c into main Nov 15, 2025
7 checks passed
@dwisiswant0 dwisiswant0 deleted the dwisiswant0/fix/sync/AdaptiveWaitGroup-counter-racy branch November 15, 2025 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sync: AdaptiveWaitGroup counter is racy, causing flaky concurrency tests (TestThrottling)

3 participants