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

- **ID:** `go/panic-sync-waitgroup-reused-before-wait`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

WaitGroup.Add() is called after Wait() has started but before it returns, violating the rule that Add must not be called concurrently with Wait.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   Ensure all Add calls happen before any Wait call. Use a single WaitGroup per logical group and don't reuse until Wait returns.
   ```
2. **** (92% success)
   ```
   Use errgroup.Group which manages lifecycle safely:
g, ctx := errgroup.WithContext(ctx)
for ... { g.Go(...) }
return g.Wait()
   ```

## Dead Ends

- **** — Sleep does not guarantee Wait has returned; race still possible. (90% fail)
- **** — If batches overlap, the same issue can occur; requires careful lifecycle management. (50% fail)
