# 致命错误：所有 goroutine 都处于休眠状态 - 死锁！（goroutine 1 [通道接收（nil 通道）]）

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

## 根因

在 nil 通道上发送或接收会永远阻塞。这发生在通道变量未初始化就使用的情况下。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   ch := make(chan int) // or with buffer: make(chan int, 10)
   ```
2. **** (85% 成功率)
   ```
   var ch chan int
select {
case v := <-ch:
    // will not execute if ch is nil
case <-time.After(time.Second):
    // handle timeout
}
   ```

## 无效尝试

- **** — The default case may execute incorrectly, and the nil channel still blocks if not handled properly. (80% 失败率)
- **** — Nil channel is a different type; assigning doesn't initialize it. (90% 失败率)
