# panic: send on closed channel (from sender after close)

- **ID:** `go/goroutine-close-channel-from-sender`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Sender goroutine sends to a channel after another goroutine has closed it, often due to race.

## Version Compatibility

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

## Workarounds

1. **Use a done channel to signal senders to stop** (85% success)
   ```
   done := make(chan struct{})
ch := make(chan int)
go func() {
    for {
        select {
        case <-done:
            return
        case ch <- 1:
        }
    }
}()
close(ch) // but close done first
close(done)
   ```
2. **Use sync.WaitGroup to ensure all sends complete before close** (90% success)
   ```
   var wg sync.WaitGroup
for i := 0; i < 5; i++ {
    wg.Add(1)
    go func() {
        defer wg.Done()
        ch <- 1
    }()
}
wg.Wait()
close(ch)
   ```

## Dead Ends

- **Using recover() to catch panic and log** — Recover doesn't fix the race; data may be lost. (90% fail)
- **Checking channel length before send** — len(ch) doesn't indicate closed state; send still panics. (95% fail)
