# 致命错误：所有 goroutine 都休眠——死锁（在 nil channel 上接收）

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

## 根因

从 nil channel 接收会永久阻塞。若 channel 变量从未被赋值却用于 select 或接收，goroutine 将永久挂起。

## 版本兼容性

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

## 解决方案

1. **** (92% 成功率)
   ```
   ch := make(chan int)
go func() { ch <- 1 }()
v := <-ch
fmt.Println(v)
   ```
2. **** (85% 成功率)
   ```
   select {
case v := <-ch:
    fmt.Println(v)
case <-ctx.Done():
    return ctx.Err()
}
   ```

## 无效尝试

- **** — It prevents the hang but the underlying nil channel is still never populated, so the program silently times out instead of working. (50% 失败率)
- **** — The default case fires immediately forever, spinning in a busy loop consuming CPU. (70% 失败率)
