go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (select with no ready case)
ID: go/select-no-default-blocks
80%Fix Rate
88%Confidence
0Evidence
2024-05-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.17 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
A select statement with no default blocks until one case becomes ready. If no channel ever becomes ready, the program deadlocks.
generic中文
没有 default 的 select 语句会阻塞直到某个 case 就绪。如果没有任何 channel 就绪,程序死锁。
Workarounds
-
95% success
select { case v := <-ch: use(v) case <-time.After(5 * time.Second): return errTimeout } -
96% success
select { case v := <-ch: use(v) case <-ctx.Done(): return ctx.Err() }
Dead Ends
Common approaches that don't work:
-
70% fail
The select now spins in a busy loop consuming CPU without ever making progress.
-
80% fail
Creates a livelock if no case is ever ready; the program hangs forever.