go
runtime_error
ai_generated
true
fatal error: 所有 goroutine 都休眠 - 死锁!(select 无就绪分支)
fatal error: all goroutines are asleep - deadlock! (select with no ready case)
ID: go/select-blocked-forever-no-default
80%修复率
88%置信度
0证据数
2024-10-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.x | active | — | — | — |
根因分析
含多个 channel 分支的 select 因没有任何分支就绪、且无 default 或超时,永久阻塞。常为生产者/消费者接线错误,预期的 channel 从未被写入。
English
A select with multiple channel cases blocks forever because no case is ever ready and there is no default or timeout. Often a producer/consumer wiring mistake where the expected channel is never written.
解决方案
-
90% 成功率
Add a context or timeout case to break the block and surface the bug: select { case v := <-ch: use(v) case <-ctx.Done(): return ctx.Err() case <-time.After(30 * time.Second): return errors.New("select timeout") } -
85% 成功率
Verify the producer actually sends on the expected channel and that the channel is not nil (sending to a nil channel blocks forever).
无效尝试
常见但无效的做法:
-
80% 失败
Turns the blocking select into a busy spin that burns CPU and still never handles the missing event.
-
70% 失败
If the root wiring is wrong, extra cases don't become ready and the deadlock persists.