# 致命错误：所有 goroutine 都处于休眠状态 - 死锁！（无缓冲通道发送无接收者）

- **ID:** `go/unbuffered-channel-deadlock-single-goroutine`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

goroutine 尝试在无缓冲通道上发送，但没有相应的接收者准备好，导致其永远阻塞。如果所有 goroutine 都阻塞，程序将死锁。

## 版本兼容性

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

## 解决方案

1. **Ensure the receiver is ready before sending** (95% 成功率)
   ```
   ch := make(chan int)
go func() {
    val := <-ch
    fmt.Println(val)
}()
ch <- 42
   ```
2. **Use a select with a default case to make send non-blocking** (90% 成功率)
   ```
   select {
case ch <- 42:
default:
    fmt.Println("no receiver, dropping message")
}
   ```

## 无效尝试

- **Using a buffered channel with size 1 to avoid blocking** — A buffered channel can hold one value, but if the receiver never reads, the buffer will fill up and subsequent sends will block, leading to the same deadlock. (85% 失败率)
- **Adding a time.Sleep before sending to wait for receiver** — Sleep is unreliable; the receiver may not be ready in time, and it introduces unnecessary delays. (90% 失败率)
