# panic: sync: negative WaitGroup counter

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

## Root Cause

Calling Done() more times than Add() causes the counter to go negative, panicking.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.18 | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   var wg sync.WaitGroup
wg.Add(1)
go func() {
    defer wg.Done()
    // work
}()
wg.Wait()
   ```
2. **** (90% success)
   ```
   // Ensure Add is called before starting goroutines
wg.Add(2)
go func() { defer wg.Done(); /* work */ }()
go func() { defer wg.Done(); /* work */ }()
wg.Wait()
   ```

## Dead Ends

- **** — Recovery doesn't fix the logic error; program state is inconsistent. (70% fail)
- **** — Panic crashes the program unless recovered. (100% fail)
- **** — Doesn't prevent negative if Done is called too many times. (80% fail)
