go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (receive from closed channel)
ID: go/channel-receive-from-closed-channel-ok
80%Fix Rate
90%Confidence
0Evidence
2024-05-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
Root Cause
A goroutine is blocked receiving from a channel that is closed and empty, but other goroutines are also blocked, leading to a deadlock.
generic中文
某个 goroutine 阻塞在从已关闭且为空的 channel 接收数据,而其他 goroutine 也处于阻塞状态,导致死锁。
Workarounds
-
95% success
v, ok := <-ch if !ok { return } -
98% success
for v := range ch { // process v }
Dead Ends
Common approaches that don't work:
-
95% fail
Sleep does not unblock a deadlock; it only delays the inevitable fatal error
-
90% fail
The deadlock is logical, not related to parallelism