Skip to content

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

@dwisiswant0

Description

@dwisiswant0

The AdaptiveWaitGroup implementation contains a race window between semaphore ops and counter updates. Under certain interleavings, the Current() value can temporarily exceed $$size + 1$$.

This manifests as flaky CI failures, especially in TestThrottling, where Current() was observed reaching 6–7 even though the configured size is 4.

What’s happening?

Both Add() and Done() update the internal counter only after their respective semaphore ops. When both ops are inflight, rapid goroutine churn can result in:

  • Add() being counted too late.
  • Done() not being counted early enough.
  • Current() reading a transient inflated value.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions