# error: context deadline exceeded (goroutine blocked on <-ch after cancel)

- **ID:** `go/goroutine-leak-on-ctx-cancel`
- **Domain:** go
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A goroutine waits on a channel that is only written on success. When ctx is cancelled the sender returns early and never sends, leaving the receiver blocked forever.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   Select on ctx.Done() alongside the channel:

select {
case v := <-ch:
    return v, nil
case <-ctx.Done():
    return nil, ctx.Err()
}
   ```
2. **** (90% success)
   ```
   Ensure producers always send or close on exit:

defer close(ch)
for _, item := range items {
    select {
    case ch <- item:
    case <-ctx.Done():
        return
    }
}
   ```

## Dead Ends

- **** — Delays the leak; cancel still leaves the receiver blocked. (70% fail)
- **** — default makes the loop spin hot and still does not deliver the value. (65% fail)
