# panic: sync: WaitGroup is reused before previous Wait has returned (racy close)

- **ID:** `go/goroutine-racy-close-waitgroup`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Calling WaitGroup.Wait() and then Add() concurrently from multiple goroutines.

## Version Compatibility

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

## Workarounds

1. **Use separate WaitGroup for each batch** (95% success)
   ```
   for batch := 0; batch < 3; batch++ {
    var wg sync.WaitGroup
    for i := 0; i < 5; i++ {
        wg.Add(1)
        go func() { defer wg.Done(); /* work */ }()
    }
    wg.Wait()
}
   ```
2. **Use channel-based synchronization** (85% success)
   ```
   ch := make(chan struct{})
for i := 0; i < 5; i++ {
    go func() { /* work */; ch <- struct{}{} }()
}
for i := 0; i < 5; i++ {
    <-ch
}
   ```

## Dead Ends

- **Using recover() to catch panic** — Panic is unrecoverable; program crashes. (100% fail)
- **Adding time.Sleep between Wait and Add** — Race condition still exists; timing-dependent. (90% fail)
