go
resource_error
ai_generated
true
goroutine leak: goroutine blocked forever on <-ch with no sender
ID: go/goroutine-leak-blocked-recv
80%Fix Rate
86%Confidence
0Evidence
2024-07-03First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
Root Cause
A receive on a channel that will never be sent to or closed leaves the goroutine parked permanently.
generic中文
对一个永远不会被发送或关闭的 channel 执行接收操作,使 goroutine 永久挂起。
Workarounds
-
94% success
select { case v := <-ch: handle(v) case <-ctx.Done(): return } -
88% success
defer close(ch)
Dead Ends
Common approaches that don't work:
-
60% fail
Ignoring the timeout branch means the goroutine still leaks if it loops; also time.After leaks timers.
-
70% fail
Closing from the receiver does not unblock the receive; the receive already returned zero value and panics on later sends.