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

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

## Root Cause

wg.Add() is called concurrently with wg.Wait(). The WaitGroup contract requires all Add calls that increment the counter to happen-before the Wait that observes them.

## 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. **** (96% success)
   ```
   g, ctx := errgroup.WithContext(context.Background())
for _, item := range items {
    item := item
    g.Go(func() error { return process(ctx, item) })
}
if err := g.Wait(); err != nil { return err }
   ```

## Dead Ends

- **** — The goroutine may start after Wait() already returned, so the counter never increments in time; still racy. (80% fail)
- **** — Timing-based synchronization is nondeterministic and fails under load or on fast machines. (95% fail)
