# panic: runtime error: send on closed channel (context cancellation)

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

## Root Cause

When a context is cancelled, its channel is closed; sending on it causes a panic.

## Version Compatibility

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

## Workarounds

1. **Use select with context.Done() to avoid sending on closed channel** (95% success)
   ```
   select {
case ch <- data:
case <-ctx.Done():
    return ctx.Err()
}
   ```
2. **Create a new channel for each operation and close it safely** (90% success)
   ```
   ch := make(chan int, 1)
select {
case ch <- data:
case <-ctx.Done():
    close(ch)
    return ctx.Err()
}
   ```

## Dead Ends

- **Checking context.Err() before send but not handling race condition** — Context can be cancelled between check and send. (70% fail)
- **Using a separate channel that is not closed on cancellation** — Ignores the cancellation signal, leading to resource leaks. (60% fail)
