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

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

## 根因

某个 goroutine 尝试向 nil channel 发送数据，这会永久阻塞。如果没有其他 goroutine 可以继续执行，运行时会检测到死锁。

## 版本兼容性

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

## 解决方案

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

## 无效尝试

- **** — A nil channel in a select will never be ready, so the default case will always be taken, silently dropping the send. (90% 失败率)
- **** — Checking for nil is not atomic and does not guarantee the channel is initialized; it may still be nil at send time. (85% 失败率)
