go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (on channel send)
ID: go/goroutine-leak-on-channel-send
80%Fix Rate
85%Confidence
0Evidence
2024-03-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
A goroutine attempts to send to a channel with no receiver and no buffer, and no other goroutine is ready to receive, causing the program to deadlock.
generic中文
一个 goroutine 尝试向没有接收者且没有缓冲的通道发送数据,且没有其他 goroutine 准备好接收,导致程序死锁。
Workarounds
-
90% success
Ensure a receiver goroutine is started before sending, or use a buffered channel with capacity ≥1 if async is acceptable.
-
85% success
Use select with default to make send non-blocking, or use a context with timeout to avoid permanent block.
Dead Ends
Common approaches that don't work:
-
70% fail
Buffering may mask the issue temporarily but doesn't solve the fundamental lack of receiver; may cause memory bloat or hidden blocking.
-
80% fail
Sleeping doesn't guarantee a receiver will appear; it's nondeterministic and may still deadlock or slow the program.