# 致命错误：所有 goroutine 都处于休眠状态 - 死锁！（goroutine 泄漏）

- **ID:** `go/goroutine-leak-on-channel-block`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Goroutine 在等待永远不会完成的通道操作时被阻塞，导致死锁。

## 版本兼容性

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

## 解决方案

1. **Use context with timeout to unblock goroutines** (90% 成功率)
   ```
   ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
select {
case <-ctx.Done():
    return
case ch <- data:
}
   ```
2. **Ensure every send has a corresponding receive in a separate goroutine** (95% 成功率)
   ```
   go func() { for v := range ch { process(v) } }()
ch <- data
   ```

## 无效尝试

- **Adding more goroutines to unblock** — More goroutines may also block if they depend on the same channels. (90% 失败率)
- **Increasing channel buffer size** — Buffering delays but does not solve the underlying missing consumer/producer. (80% 失败率)
