Skip to content
Critiq Docs

Search docs

Search documentation pages and rules

correctness.concurrency

Call WaitGroup.Add before launching the goroutine

WaitGroup.Add called inside the goroutine races with Wait.

#Metadata

Rule ID
go.correctness.waitgroup-add-in-goroutine
Severity
high
Confidence
0.88
Languages
go
Presets
strict
Stability
stable
Applies to
block
Tags
concurrency, correctness, go, rules-catalog

#Why it matters

`sync.WaitGroup.Add` must happen before the launching goroutine returns to the caller. If `Add` runs inside the goroutine, `Wait` may observe a zero counter and return before the work begins.

#Remediation

Call `wg.Add(n)` on the launching goroutine before the `go` statement starts the worker.

#Repository path

The generated metadata points to critiq-rules/libs/rules/catalog/rules/go/go.correctness.waitgroup-add-in-goroutine.rule.yaml.