go
runtime_error
ai_generated
true
fatal error: 所有 goroutine 都休眠了 - 死锁!(从已关闭的 channel 接收)
fatal error: all goroutines are asleep - deadlock! (receive from closed channel)
ID: go/channel-receive-from-closed-channel-ok
80%修复率
90%置信度
0证据数
2024-05-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
根因分析
某个 goroutine 阻塞在从已关闭且为空的 channel 接收数据,而其他 goroutine 也处于阻塞状态,导致死锁。
English
A goroutine is blocked receiving from a channel that is closed and empty, but other goroutines are also blocked, leading to a deadlock.
解决方案
-
95% 成功率
v, ok := <-ch if !ok { return } -
98% 成功率
for v := range ch { // process v }
无效尝试
常见但无效的做法:
-
95% 失败
Sleep does not unblock a deadlock; it only delays the inevitable fatal error
-
90% 失败
The deadlock is logical, not related to parallelism