# 致命错误：所有 goroutine 都处于休眠状态 - 死锁！（选择包含 nil 通道）

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

## 根因

一个选择语句有多个 case，但所有通道都是 nil。在 Go 中，所有通道都是 nil 的选择会永远阻塞，因为没有 case 可以执行。

## 版本兼容性

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

## 解决方案

1. **Ensure all channels in select are non-nil** (95% 成功率)
   ```
   ch1 := make(chan int)
ch2 := make(chan int)
select {
case <-ch1:
case <-ch2:
}
   ```
2. **Use a helper function to filter out nil channels** (90% 成功率)
   ```
   func nonNilChannels(chs ...chan int) []chan int {
    var result []chan int
    for _, ch := range chs {
        if ch != nil {
            result = append(result, ch)
        }
    }
    return result
}
   ```

## 无效尝试

- **Adding a default case to the select** — A default case will execute immediately if all channels are nil, but it doesn't solve the underlying issue of nil channels; it just avoids the block. (80% 失败率)
- **Removing the select and using direct channel operations** — Direct operations on nil channels will also block forever, so this doesn't help. (95% 失败率)
