panic: sync: negative WaitGroup counter Go Origin: Application & API Last updated 4 Nov 2026

Go: panic: sync: negative WaitGroup counter

wg.Done() was called more times than wg.Add().

Exact message you may see panic: sync: negative WaitGroup countersync: negative WaitGroup countersync: WaitGroup is reused before previous Wait has returnedWaitGroup misuse: Add called concurrently with Wait
Seen on: Go

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

  1. wg.Add(1) before go func(){ defer wg.Done() … }()
  2. Pass *sync.WaitGroup, not a copy
  3. Use go vet (copylocks) to catch copies

Detailed fix by platform

Go

  1. go vet ./... reports passing sync.WaitGroup by value

How to diagnose

  1. Pairing — Add and Done balanced?
  2. Copy — Passed by pointer?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

all goroutines are asleep - deadlock — Go: fatal error: all goroutines are asleep - deadlock! (Go)all goroutines are as…fatal error: concurrent map read and map write — Go: fatal error: concurrent map read and map write (Go)fatal error: concurre…fatal error: concurrent map writes — Go: fatal error: concurrent map writes (Go)fatal error: concurre…listen tcp :8080: bind: address already in use — Go: listen tcp :8080: bind: address already in use (Go)listen tcp :8080: bin…panic: close of closed channel — Go: panic: close of closed channel (or close of nil channel) (Go)panic: close of close…panic: send on closed channel — Go: panic: send on closed channel (Go)panic: send on closed…panic: test timed out after 10m0s — Go: panic: test timed out after 10m0s — running tests: TestFoo (10m0s) (Go)panic: test timed out…WARNING: DATA RACE — Go: WARNING: DATA RACE — Write at 0x00c0000 by goroutine 7: / Previous read at ... by goroutine 6 (Go)WARNING: DATA RACEpanic: sy…

Explore the map of this error Full error map →

🧠 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.