# panic: close of nil channel

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

## Root Cause

Calling close() on a nil channel, which is a programming error.

## Version Compatibility

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

## Workarounds

1. **Initialize channel before close** (99% success)
   ```
   ch := make(chan int)
// use ch
close(ch)
   ```
2. **Use sync.Once to safely close only if initialized** (85% success)
   ```
   var once sync.Once
if ch != nil {
    once.Do(func() { close(ch) })
}
   ```

## Dead Ends

- **Using recover() to catch panic** — Recover works but doesn't fix the logic; channel remains nil. (90% fail)
- **Checking ch != nil before close but not initializing** — Nil check prevents panic but channel is never initialized; subsequent operations fail. (80% fail)
