go
runtime_error
ai_generated
true
致命错误:所有 goroutine 处于休眠状态 - 死锁! goroutine 1 [select (no cases)]:
fatal error: all goroutines are asleep - deadlock! goroutine 1 [select (no cases)]:
ID: go/select-no-case-ready-blocks-forever
80%修复率
89%置信度
0证据数
2024-09-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
根因分析
select 语句没有就绪的 case 也没有 default,永久阻塞。如果它是唯一可运行的 goroutine,运行时会报告死锁。
English
A select statement has no ready cases and no default, blocking forever. If it's the only runnable goroutine, the runtime reports deadlock.
解决方案
-
92% 成功率
select { case v := <-ch: return v case <-time.After(5 * time.Second): return errors.New("timeout") } -
95% 成功率
select { case v := <-ch: return v, nil case <-ctx.Done(): return nil, ctx.Err() }
无效尝试
常见但无效的做法:
-
85% 失败
Turns a blocking wait into a busy loop that spins CPU at 100%.
-
80% 失败
Polling with sleeps adds latency and still misses events under load.