Skip to content

waitgroup-add-inside-goroutine

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.

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