# 恐慌：运行时错误：在nil通道上选择

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

## 根因

在select语句中使用nil通道，导致永久阻塞和潜在死锁。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.18 | active | — | — |
| 1.19 | active | — | — |
| 1.20 | active | — | — |
| 1.21 | active | — | — |
| 1.22 | active | — | — |

## 解决方案

1. **Initialize channels before use in select** (95% 成功率)
   ```
   ch := make(chan int); select { case v := <-ch: // use v }
   ```
2. **Check for nil before select** (90% 成功率)
   ```
   if ch != nil { select { case v := <-ch: // } }
   ```

## 无效尝试

- **Adding default case without fixing nil** — Default case executes but nil channel still blocks if selected. (80% 失败率)
- **Using recover() to ignore** — Does not fix nil channel issue. (90% 失败率)
