# 致命错误：所有协程都处于休眠状态 - 死锁！（从 nil 通道接收）

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

## 根因

协程尝试从 nil 通道接收数据，这会导致无限阻塞，如果没有其他协程可以解除阻塞，则会导致死锁。

## 版本兼容性

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

## 解决方案

1. **Ensure channel is initialized before use** (100% 成功率)
   ```
   ch := make(chan int)
// use ch
   ```
2. **Use a default case in select to avoid blocking** (90% 成功率)
   ```
   select {
case val := <-ch:
    // process
case <-time.After(1 * time.Second):
    // timeout
}
   ```

## 无效尝试

- **Initialize channel in init()** — If the channel is used before init() runs, it remains nil. (60% 失败率)
- **Ignore the nil channel and add a timeout** — Timeout doesn't fix the root cause; the channel is still nil and will block again. (80% 失败率)
