go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (send on nil chan)
ID: go/send-on-nil-channel-block
80%Fix Rate
87%Confidence
0Evidence
2024-09-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.x | active | — | — | — |
Root Cause
Sending or receiving on a nil channel blocks forever. Often a channel field was never initialized.
generic中文
向 nil channel 发送或接收会永久阻塞。通常是 channel 字段未初始化。
Workarounds
-
95% success
func New() *Worker { return &Worker{ch: make(chan int, 16)} } -
90% success
if w.ch == nil { return errors.New("worker channel not initialized") } w.ch <- v
Dead Ends
Common approaches that don't work:
-
70% fail
Default fires immediately, silently dropping messages instead of fixing the nil.
-
65% fail
Turns a deadlock into a timeout but the channel is still nil and unusable.