# fatal error: 所有 goroutine 都处于休眠状态 - 死锁！（在 nil channel 上 select）

- **ID:** `go/select-on-empty-nil-channel`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

select 中只有 nil channel（或单个 nil channel）会永久阻塞，因为 nil channel 永不就绪。常见于条件性地将 channel 赋值为 nil 以禁用某个 case。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.0+ | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   select {
case v := <-ch:
    handle(v)
case <-ctx.Done():
    return ctx.Err()
}
   ```
2. **** (92% 成功率)
   ```
   if ch == nil { return ErrNoChannel }
select { case v := <-ch: _ = v }
   ```

## 无效尝试

- **** — Turns the deadlock into a busy loop, pegging CPU and never making progress. (85% 失败率)
- **** — Unbuffered channel still blocks if no sender; same deadlock. (80% 失败率)
