# panic: sync: negative WaitGroup counter

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

## Root Cause

Calling Done() more times than Add() was called, decrementing counter below zero.

## Version Compatibility

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

## Workarounds

1. **Ensure Add() is called exactly once per goroutine that will call Done()** (95% success)
   ```
   var wg sync.WaitGroup
for i := 0; i < n; i++ {
    wg.Add(1)
    go func() { defer wg.Done(); work() }()
}
wg.Wait()
   ```
2. **Use defer wg.Done() immediately after wg.Add() in the goroutine** (90% success)
   ```
   go func() { defer wg.Done(); ... }()
   ```

## Dead Ends

- **Increasing Add() count arbitrarily** — If Done() is called extra times, the counter still goes negative. (85% fail)
- **Ignoring the panic and continuing** — Panic stops execution; ignoring it is not possible. (100% fail)
