go
resource_error
ai_generated
true
goroutine 泄漏: N 个 goroutine 阻塞在 chan send(通过 pprof 检测)
goroutine leak: N goroutines blocked in chan send (detected via pprof)
ID: go/goroutine-leak-blocked-send
80%修复率
87%置信度
0证据数
2024-08-14首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
根因分析
启动的 goroutine 向无缓冲或已满的 channel 发送数据,但接收方已停止读取,导致它们永久阻塞并不断累积。
English
Goroutines were spawned to send on an unbuffered or full channel whose receiver stopped reading, so they block forever and accumulate.
解决方案
-
95% 成功率
select { case ch <- v: case <-ctx.Done(): return } -
90% 成功率
jobs := make(chan Job, 128) for i := 0; i < runtime.NumCPU(); i++ { go func() { for j := range jobs { process(j) } }() }
无效尝试
常见但无效的做法:
-
95% 失败
Blocked goroutines are not CPU-bound; more CPUs do not unblock them and memory keeps growing.
-
90% 失败
GC does not collect goroutines blocked on channels; they remain reachable from the scheduler.