go
runtime_error
ai_generated
true
fatal error:所有 goroutine 都休眠——死锁!(空 select{})
fatal error: all goroutines are asleep - deadlock! (empty select{})
ID: go/select-empty-blocks-forever
80%修复率
85%置信度
0证据数
2024-09-16首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.17 | active | — | — | — |
| 1.21 | active | — | — | — |
根因分析
空 select{} 永远阻塞且没有 case。若主 goroutine 在其上阻塞且无其他存活 goroutine,运行时会报告死锁。
English
An empty select{} blocks forever with no cases. If the main goroutine hits it without other live goroutines, the runtime reports deadlock.
解决方案
-
96% 成功率
sig := make(chan os.Signal, 1) signal.Notify(sig, os.Interrupt, syscall.SIGTERM) <-sig
-
95% 成功率
<-ctx.Done()
无效尝试
常见但无效的做法:
-
85% 失败
Busy-spins and consumes 100% CPU; not a real fix for missing shutdown logic.
-
95% 失败
The select{} never returns, so the sleep is unreachable.