# panic: sync: WaitGroup misuse: Add called concurrently with Wait

- **ID:** `go/context-cancellation-race`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Calling Add() on a WaitGroup concurrently with Wait(), often due to canceling context that triggers new goroutines while waiting.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   Ensure all Add calls happen before Wait by using a separate goroutine to start workers: 

var wg sync.WaitGroup
for i := 0; i < n; i++ {
    wg.Add(1)
    go func() { defer wg.Done(); /* work */ }()
}
wg.Wait()
   ```
2. **** (90% success)
   ```
   Use a channel to signal completion instead of WaitGroup when dynamic goroutine creation is needed.
   ```

## Dead Ends

- **** — Doesn't prevent Add from being called after Wait has started. (80% fail)
- **** — If goroutines are started from a context cancellation callback, it may be too late. (60% fail)
