go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (empty select{})
ID: go/select-no-cases-blocks-forever
80%Fix Rate
85%Confidence
0Evidence
2024-07-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
An empty select{} blocks the goroutine forever. If it's the main goroutine and nothing else can make progress, the runtime reports deadlock.
generic中文
空 select{} 永久阻塞 goroutine。若为主 goroutine 且无其他进度,运行时会报告死锁。
Workarounds
-
90% success
Block on a signal channel instead of empty select: quit := make(chan os.Signal, 1) signal.Notify(quit, os.Interrupt) <-quit
-
92% success
Use sync.WaitGroup to wait for real work completion: wg.Wait()
Dead Ends
Common approaches that don't work:
-
70% fail
Still blocks; program never exits and deadlock detection is defeated.
-
60% fail
Goroutine leaks and main may exit before work completes.