# 致命错误：所有 goroutine 都处于休眠状态 - 死锁！（在 nil 通道上 select）

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

## 根因

包含 nil 通道的 select 语句会永远阻塞，因为对 nil 通道的发送/接收会无限期阻塞。

## 版本兼容性

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

## 解决方案

1. **Initialize channels before using in select** (95% 成功率)
   ```
   ch := make(chan int)
select {
case <-ch:
    // handle
case <-time.After(time.Second):
    // timeout
}
   ```
2. **Use a non-nil placeholder channel if channel may be nil** (85% 成功率)
   ```
   if ch == nil { ch = make(chan int) } // but ensure it's used properly
   ```

## 无效尝试

- **Adding a default case to select** — Default case runs if all channels are nil, but if only some are nil, it may still block. (70% 失败率)
- **Checking channel for nil before select** — If channel becomes nil dynamically, race condition may occur. (80% 失败率)
