# goroutine 泄漏：N 个 goroutine 阻塞在 chan receive（由 goleak 检测）

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

## 根因

goroutine 永远阻塞在 channel 接收上，因为发送方已退出或 channel 从未关闭。

## 版本兼容性

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

## 解决方案

1. **** (92% 成功率)
   ```
   Pass a context.Context and select on ctx.Done(): select { case v := <-ch: handle(v); case <-ctx.Done(): return }.
   ```
2. **** (90% 成功率)
   ```
   Ensure the sender closes the channel when finished: defer close(ch) in the producer, so receivers unblock with the zero value.
   ```

## 无效尝试

- **** — Buffering delays the block but does not prevent it once the buffer fills; the leak returns under load. (80% 失败率)
- **** — Blocked goroutines are reachable and not garbage collected; GC cannot reclaim them. (95% 失败率)
