# fatal error: 所有 goroutine 都处于休眠状态 - 死锁！（nil channel 接收）

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

## 根因

某个 goroutine 尝试从 nil channel 接收数据，这会永久阻塞。如果所有 goroutine 都阻塞在 nil channel 上，运行时会检测到死锁。

## 版本兼容性

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

## 解决方案

1. **** (98% 成功率)
   ```
   ch := make(chan int)
// or ch := make(chan int, 1)
   ```
2. **** (90% 成功率)
   ```
   select {
case v := <-ch:
    // use v
case <-time.After(1 * time.Second):
    return errors.New("timeout: channel may be nil")
}
   ```

## 无效尝试

- **** — A nil channel is not the same as an uninitialized variable; you must explicitly create it with make(). (90% 失败率)
- **** — A select with a nil channel case will block if no other case is ready; default only helps if you want non-blocking behavior. (85% 失败率)
