# 错误：在 nil 通道上的 select 永久阻塞

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

## 根因

向 nil 通道发送或从 nil 通道接收会永久阻塞。在 select 中，nil 通道分支永远不会就绪，若所有分支都是 nil，select 会无限阻塞。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   var ch chan int = make(chan int)
select {
case v := <-ch: _ = v
case <-time.After(time.Second):
}
   ```
2. **** (85% 成功率)
   ```
   var never chan struct{} // nil disables the case
select {
case <-never:
case <-ch:
}
   ```

## 无效尝试

- **** — With default, the select always takes the default branch, so nothing ever happens; the intended wait is lost. (85% 失败率)
- **** — The outer select still holds the nil reference; the goroutine's new channel is unrelated. (75% 失败率)
