# panic: sync: negative WaitGroup counter

- **ID:** `go/panic-sync-negative-waitgroup-counter`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

wg.Done() called more times than wg.Add(), typically from double-decrement or Done in a loop without matching Add.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.0+ | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   wg.Add(1)
go func() {
    defer wg.Done()
    work()
}()
   ```
2. **** (92% success)
   ```
   g, ctx := errgroup.WithContext(context.Background())
g.Go(func() error { return work(ctx) })
return g.Wait()
   ```

## Dead Ends

- **** — Panic is thrown inside sync.WaitGroup internal state; recover in the goroutine may catch it but leaves the counter corrupted. (80% fail)
- **** — Masks the bug; wg.Wait() then blocks forever because counter never reaches zero. (85% fail)
