go
runtime_error
ai_generated
true
致命错误: 所有 goroutine 都处于休眠状态 - 死锁!(select 无就绪分支)
fatal error: all goroutines are asleep - deadlock! (select with no ready case)
ID: go/select-no-case-ready-timeout
80%修复率
88%置信度
0证据数
2024-09-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
根因分析
select 语句没有 default 分支,且其 channel 分支都未就绪,也没有其他 goroutine 能使它们就绪,导致全局死锁。
English
A select statement has no default and none of its channel cases are ready, and no other goroutine can make them ready, causing a global deadlock.
解决方案
-
90% 成功率
Add a timeout case with time.After and return an error on expiry.
-
85% 成功率
Ensure at least one case is a send that can always proceed, or restructure so the producer runs before the select.
无效尝试
常见但无效的做法:
-
70% 失败
Busy-looping burns CPU and may still never see data if the producer is also blocked.