# panic: close of nil channel

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

## Root Cause

close() is called on a channel variable that was never initialized with make(), so it holds the nil zero value.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   Initialize the channel at declaration: ch := make(chan int). Never use var ch chan int without assignment if it will be closed.
   ```
2. **** (93% success)
   ```
   Use a struct constructor that always makes the channel, e.g. func NewWorker() *Worker { return &Worker{jobs: make(chan Job)} }.
   ```

## Dead Ends

- **** — Skipping the close leaves the channel open forever, so receivers block indefinitely; the underlying logic bug remains. (75% fail)
- **** — Creating a fresh channel at close time means no other goroutine holds a reference to it; the close is meaningless. (85% fail)
