go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (send on nil channel)
ID: go/send-on-nil-channel-blocks
80%Fix Rate
89%Confidence
0Evidence
2024-05-30First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
Sending to or receiving from a nil channel blocks forever. If all goroutines do this, the runtime reports deadlock.
generic中文
向 nil channel 发送或接收会永久阻塞。如果所有 goroutine 都这样,运行时会报告死锁。
Workarounds
-
95% success
ch := make(chan int)
-
85% success
if ch == nil { return } ch <- v
Dead Ends
Common approaches that don't work:
-
70% fail
Default turns a blocking send into a busy-loop or dropped message, not a fix for the nil channel.
-
85% fail
More goroutines blocked on nil channel just produce the same deadlock.