# 致命错误：所有goroutine都在休眠 - 死锁！（无缓冲通道）

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

## 根因

无缓冲通道要求发送方和接收方同时就绪。如果只有一方就绪，就会无限期阻塞。

## 版本兼容性

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

## 解决方案

1. **Ensure both sender and receiver are started before the blocking operation** (90% 成功率)
   ```
   ch := make(chan int)

go func() {
    val := <-ch
    fmt.Println(val)
}()

ch <- 42 // now this won't block because receiver is ready
   ```
2. **Use a buffered channel with a reasonable capacity** (80% 成功率)
   ```
   ch := make(chan int, 10) // buffer size 10
   ```

## 无效尝试

- **Making the channel buffered with a small size** — A small buffer may not be sufficient; if the buffer fills up, the same deadlock can occur. (50% 失败率)
- **Using time.Sleep to give the other side time to prepare** — Sleeping is non-deterministic and doesn't guarantee both sides are ready; it may still deadlock. (75% 失败率)
