go
runtime_error
ai_generated
true
fatal error: 所有 goroutine 都休眠了 - 死锁!(select 无 case)
fatal error: all goroutines are asleep - deadlock! (select with no cases)
ID: go/select-empty-deadlock
80%修复率
90%置信度
0证据数
2024-04-18首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
根因分析
select 语句没有任何 case,会永远阻塞,如果所有 goroutine 都阻塞,运行时会检测到死锁。
English
A select statement with no cases blocks forever, and if all goroutines are blocked, the runtime detects deadlock.
解决方案
-
98% 成功率
select { case <-ch: // handle } -
95% 成功率
select { case <-done: return case <-ch: // handle }
无效尝试
常见但无效的做法:
-
60% 失败
Default case may cause busy loop and still not solve logical deadlock
-
90% 失败
Sleep does not help; select with no cases is invalid