go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (goroutine leak)
ID: go/goroutine-leak-on-channel-block
80%Fix Rate
85%Confidence
0Evidence
2024-05-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0 | active | — | — | — |
| 1.21 | active | — | — | — |
Root Cause
Goroutines are blocked waiting on channel operations that never complete, leading to a deadlock.
generic中文
Goroutine 在等待永远不会完成的通道操作时被阻塞,导致死锁。
Workarounds
-
90% success Use context with timeout to unblock goroutines
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() select { case <-ctx.Done(): return case ch <- data: } -
95% success Ensure every send has a corresponding receive in a separate goroutine
go func() { for v := range ch { process(v) } }() ch <- data
Dead Ends
Common approaches that don't work:
-
Adding more goroutines to unblock
90% fail
More goroutines may also block if they depend on the same channels.
-
Increasing channel buffer size
80% fail
Buffering delays but does not solve the underlying missing consumer/producer.