go
resource_error
ai_generated
true
goroutine leak: N goroutines blocked in chan send (detected via pprof)
ID: go/goroutine-leak-blocked-send
80%Fix Rate
87%Confidence
0Evidence
2024-08-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
Root Cause
Goroutines were spawned to send on an unbuffered or full channel whose receiver stopped reading, so they block forever and accumulate.
generic中文
启动的 goroutine 向无缓冲或已满的 channel 发送数据,但接收方已停止读取,导致它们永久阻塞并不断累积。
Workarounds
-
95% success
select { case ch <- v: case <-ctx.Done(): return } -
90% success
jobs := make(chan Job, 128) for i := 0; i < runtime.NumCPU(); i++ { go func() { for j := range jobs { process(j) } }() }
Dead Ends
Common approaches that don't work:
-
95% fail
Blocked goroutines are not CPU-bound; more CPUs do not unblock them and memory keeps growing.
-
90% fail
GC does not collect goroutines blocked on channels; they remain reachable from the scheduler.