go
runtime_error
ai_generated
true
致命错误:所有 goroutine 都处于休眠状态 - 死锁!(涉及 2 个通道)
fatal error: all goroutines are asleep - deadlock! (with 2 channels)
ID: go/deadlock-multiple-channels
80%修复率
81%置信度
0证据数
2024-04-18首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
根因分析
两个 goroutine 各自等待对方发送数据的通道,导致循环等待。
English
Two goroutines each waiting on a channel that the other is supposed to send to, causing a circular wait.
解决方案
-
90% 成功率
ch1 := make(chan int) ch2 := make(chan int) go func() { ch1 <- 1; <-ch2 }() go func() { ch2 <- 2; <-ch1 }() -
85% 成功率
select { case v := <-ch1: // handle case <-time.After(time.Second): // timeout }
无效尝试
常见但无效的做法:
-
80% 失败
Buffers only help if sends don't block; in circular wait, both block indefinitely.
-
60% 失败
If both use timeouts, they may repeatedly timeout without progress.
-
70% 失败
More goroutines don't resolve circular dependency; they may also block.