# context canceled

- **ID:** `go/context-canceled-in-goroutine`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A context was canceled (either by timeout, deadline, or explicit cancel) while a goroutine was still using it. The goroutine receives context.Canceled error from a function that respects the context.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.7+ | active | — | — |

## Workarounds

1. **** (98% success)
   ```
   select {
case <-ctx.Done():
    return ctx.Err()
default:
    // continue
}
   ```
2. **** (95% success)
   ```
   ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
   ```

## Dead Ends

- **** — Ignoring cancellation can lead to resource leaks, wasted work, and violating the contract of context-aware functions. (95% fail)
- **** — This loses the cancellation signal and any deadlines, potentially causing the goroutine to run indefinitely. (90% fail)
