go runtime_error ai_generated true

fatal error: all goroutines are asleep - deadlock! (send on nil channel)

ID: go/send-on-nil-channel-blocks

Also available as: JSON · Markdown · 中文
80%Fix Rate
89%Confidence
0Evidence
2024-05-30First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 95% success
    ch := make(chan int)
  2. 85% success
    if ch == nil { return }
    ch <- v

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Default turns a blocking send into a busy-loop or dropped message, not a fix for the nil channel.

  2. 85% fail

    More goroutines blocked on nil channel just produce the same deadlock.