Skip to content

waitgroup-add-inside-goroutine

Detect WaitGroup.Add calls inside newly started goroutines.

Updated View as Markdown

Default severity: error

WaitGroup.Add must happen before starting the goroutine it accounts for. Calling Add inside the goroutine races with Wait, which may observe a zero counter and return too early.

Bad

go func() { group.Add(1); defer group.Done() }()

Good

group.Add(1)
go func() { defer group.Done() }()
Navigation

Type to search…

↑↓ navigate↵ selectEsc close