# goroutine 泄漏：goroutine 阻塞在通道接收

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

## 根因

一个 goroutine 等待从通道接收数据，但该通道从未被发送或关闭，通常是因为发送方退出时未关闭通道。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Use select with context:
select {
case v := <-ch:
    _ = v
case <-ctx.Done():
    return
}
   ```
2. **** (92% 成功率)
   ```
   Ensure the sender closes the channel when done. Use defer close(ch) in the sender goroutine.
   ```

## 无效尝试

- **** — time.After allocates a timer each call and can leak timers; also doesn't fix the root cause. (60% 失败率)
- **** — Closing from receiver can cause panic if sender later sends; violates channel ownership. (80% 失败率)
