# panic: send on closed channel

- **ID:** `go/send-on-closed-channel`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Sending data to a channel that has been closed.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.0 | active | — | — |
| 1.21 | active | — | — |

## Workarounds

1. **Ensure no sends after close by using a done channel pattern** (95% success)
   ```
   done := make(chan struct{})
// producer loop
select {
case <-done:
    return
case ch <- data:
}
// closer
close(ch); close(done)
   ```
2. **Use a mutex to synchronize close and sends** (90% success)
   ```
   var mu sync.Mutex
var closed bool
mu.Lock()
if closed { mu.Unlock(); return }
ch <- data
mu.Unlock()
   ```

## Dead Ends

- **Checking if channel is closed before sending via a flag** — Race condition: the channel may be closed between the check and the send. (85% fail)
- **Using recover() to catch panic and continue** — Recovering from panic is possible but indicates design flaw; data may be lost. (70% fail)
