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

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

## Root Cause

wg.Add called again while another goroutine is still in wg.Wait. Typically happens with a loop that reuses the same WaitGroup across iterations without resetting.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.20 | active | — | — |
| 1.23 | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   for _, batch := range batches {
    var wg sync.WaitGroup
    for _, x := range batch {
        wg.Add(1)
        go func(x int) { defer wg.Done(); work(x) }(x)
    }
    wg.Wait()
}
   ```
2. **** (93% success)
   ```
   for _, batch := range batches {
    g := new(errgroup.Group)
    for _, x := range batch { x := x; g.Go(func() error { return work(x) }) }
    if err := g.Wait(); err != nil { return err }
}
   ```

## Dead Ends

- **** — Reassigning while Wait is in flight races on the struct; still panics or corrupts state. (85% fail)
- **** — Sleep does not synchronize with Wait's completion; race remains. (80% fail)
