go
resource_error
ai_generated
true
goroutine leak: N goroutines blocked in chan send (runtime.gopark)
ID: go/goroutine-leak-blocked-channel
80%Fix Rate
87%Confidence
0Evidence
2024-05-09First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.7+ | active | — | — | — |
Root Cause
Goroutines send to an unbuffered channel whose receiver has exited or never runs, so they block forever. Memory and goroutine count grow unbounded over time.
generic中文
goroutine 向无缓冲通道发送数据,但接收方已退出或从未运行,导致永久阻塞。内存和 goroutine 数量随时间无限增长。
Workarounds
-
95% success
select { case out <- v: case <-ctx.Done(): return ctx.Err() } -
82% success
ch := make(chan int, len(producers)) // producers can always send without blocking
Dead Ends
Common approaches that don't work:
-
95% fail
GOMAXPROCS controls scheduler parallelism, not goroutine blocking; blocked goroutines remain blocked.
-
90% fail
Blocked goroutines are reachable from the scheduler and are not collected; GC cannot free them.