go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (nil channel)
ID: go/channel-nil-block-forever
80%Fix Rate
90%Confidence
0Evidence
2024-04-02First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
Root Cause
Sending or receiving on a nil channel blocks forever, leading to deadlock if all goroutines are blocked.
generic中文
在 nil channel 上发送或接收会永远阻塞,如果所有 goroutine 都阻塞,则导致死锁。
Workarounds
-
98% success
ch := make(chan int)
-
90% success
if ch != nil { ch <- v }
Dead Ends
Common approaches that don't work:
-
90% fail
Timeout on nil channel still blocks; select with timeout won't trigger
-
70% fail
Default case may cause busy loop