# panic: close of closed channel

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

## Root Cause

Calling close() on a channel that has already been closed, typically due to multiple goroutines attempting to close the same channel.

## Version Compatibility

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

## Workarounds

1. **Use sync.Once to ensure close is called only once** (99% success)
   ```
   var closeOnce sync.Once
closeOnce.Do(func() {
    close(ch)
})
   ```
2. **Designate a single goroutine to close the channel** (98% success)
   ```
   // Only one goroutine has access to close(ch)
ch := make(chan int)
go func() {
    // close when done
    close(ch)
}()
   ```

## Dead Ends

- **Checking if channel is closed before closing** — No built-in way to check if a channel is closed without risking a race condition. (80% fail)
- **Using recover() to catch panic** — Recover does not prevent the panic from occurring; it only catches it after the fact. (85% fail)
