go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (empty select{})
ID: go/select-empty-blocks-forever
80%Fix Rate
85%Confidence
0Evidence
2024-09-16First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.17 | active | — | — | — |
| 1.21 | active | — | — | — |
Root Cause
An empty select{} blocks forever with no cases. If the main goroutine hits it without other live goroutines, the runtime reports deadlock.
generic中文
空 select{} 永远阻塞且没有 case。若主 goroutine 在其上阻塞且无其他存活 goroutine,运行时会报告死锁。
Workarounds
-
96% success
sig := make(chan os.Signal, 1) signal.Notify(sig, os.Interrupt, syscall.SIGTERM) <-sig
-
95% success
<-ctx.Done()
Dead Ends
Common approaches that don't work:
-
85% fail
Busy-spins and consumes 100% CPU; not a real fix for missing shutdown logic.
-
95% fail
The select{} never returns, so the sleep is unreachable.