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

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

## Root Cause

Add() is called on a WaitGroup while another goroutine is still blocked in Wait(), which the runtime forbids to prevent counter races.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.20 | active | — | — |
| 1.21 | active | — | — |
| 1.22 | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   var wg sync.WaitGroup
for i := 0; i < n; i++ { wg.Add(1) }
for i := 0; i < n; i++ {
    go func() { defer wg.Done(); work() }()
}
wg.Wait()
   ```
2. **** (93% success)
   ```
   sem := make(chan struct{}, 10)
var wg sync.WaitGroup
for _, job := range jobs {
    sem <- struct{}{}
    wg.Add(1)
    go func(j Job) {
        defer wg.Done()
        defer func() { <-sem }()
        run(j)
    }(job)
}
wg.Wait()
   ```

## Dead Ends

- **** — Wait() may return before the goroutine even starts, so Add happens after Wait and the counter update races. (80% fail)
- **** — Sleep does not synchronize Add with Wait; under load the panic still occurs. (70% fail)
