# panic: sync: WaitGroup is reused before previous Wait has returned

- **ID:** `go/waitgroup-added-after-wait`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

wg.Add() was called from a goroutine while another goroutine was blocked in wg.Wait(), or the WaitGroup was reused across batches without synchronization.

## Version Compatibility

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

## Workarounds

1. **** (97% success)
   ```
   var wg sync.WaitGroup
for _, item := range items {
    wg.Add(1)
    go func(it Item) {
        defer wg.Done()
        process(it)
    }(item)
}
wg.Wait()
   ```
2. **** (93% success)
   ```
   for _, batch := range batches {
    var wg sync.WaitGroup
    for _, x := range batch {
        wg.Add(1)
        go func(v X) { defer wg.Done(); work(v) }(x)
    }
    wg.Wait()
}
   ```

## Dead Ends

- **** — The ordering of Add vs Wait is the actual constraint; moving Wait just changes where the race manifests and can cause premature return. (75% fail)
- **** — No happens-before guarantee; under load the Add still races with Wait. (80% fail)
