Go: panic: sync: negative WaitGroup counter
wg.Done() was called more times than wg.Add().
panic: sync: negative WaitGroup countersync: negative WaitGroup countersync: WaitGroup is reused before previous Wait has returnedWaitGroup misuse: Add called concurrently with Wait Meaning
Each goroutine should call Done exactly once, usually via defer wg.Done(), after a matching Add(1) made before the goroutine starts. Calling Add inside the goroutine races with Wait. The related panic "WaitGroup is reused before previous Wait has returned" signals reuse bugs.
Common causes
- Done() called twice per goroutine
- Add(n) smaller than the number of goroutines
- Add called inside the goroutine
- WaitGroup copied by value (passed without pointer)
- Reuse across loops
⚡ Quick fix
wg.Add(1)beforego func(){ defer wg.Done() … }()- Pass
*sync.WaitGroup, not a copy - Use
go vet(copylocks) to catch copies
Detailed fix by platform
Go
go vet ./...reports passing sync.WaitGroup by value
How to diagnose
- Pairing — Add and Done balanced?
- Copy — Passed by pointer?
- Timing — Add before go?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Go
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026