go
runtime_error
ai_generated
true
致命错误:所有goroutine都处于休眠状态 - 死锁!(select没有可用的case)
fatal error: all goroutines are asleep - deadlock! (select with no cases)
ID: go/select-no-case-ready
80%修复率
87%置信度
0证据数
2024-05-30首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.0 | active | — | — | — |
| 1.21 | active | — | — | — |
根因分析
select语句没有任何case就绪,也没有default,导致goroutine永久阻塞。
English
A select statement has no case that is ready, and no default, causing the goroutine to block forever.
解决方案
-
90% 成功率
Ensure at least one channel in the select will eventually receive or send. Use context or done channels.
-
85% 成功率
Include a default case to handle the situation when no channel is ready.
无效尝试
常见但无效的做法:
-
60% 失败
Adding default changes the semantics; it may cause busy looping.
-
80% 失败
Sleep does not guarantee that channels will become ready; it just delays.
-
70% 失败
This may break the logic and cause other issues.