go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (with 2 channels)
ID: go/deadlock-multiple-channels
80%Fix Rate
81%Confidence
0Evidence
2024-04-18First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
Root Cause
Two goroutines each waiting on a channel that the other is supposed to send to, causing a circular wait.
generic中文
两个 goroutine 各自等待对方发送数据的通道,导致循环等待。
Workarounds
-
90% success
ch1 := make(chan int) ch2 := make(chan int) go func() { ch1 <- 1; <-ch2 }() go func() { ch2 <- 2; <-ch1 }() -
85% success
select { case v := <-ch1: // handle case <-time.After(time.Second): // timeout }
Dead Ends
Common approaches that don't work:
-
80% fail
Buffers only help if sends don't block; in circular wait, both block indefinitely.
-
60% fail
If both use timeouts, they may repeatedly timeout without progress.
-
70% fail
More goroutines don't resolve circular dependency; they may also block.