go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! goroutine 1 [select (no cases)]:
ID: go/select-no-case-ready-blocks-forever
80%Fix Rate
89%Confidence
0Evidence
2024-09-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
Root Cause
A select statement has no ready cases and no default, blocking forever. If it's the only runnable goroutine, the runtime reports deadlock.
generic中文
select 语句没有就绪的 case 也没有 default,永久阻塞。如果它是唯一可运行的 goroutine,运行时会报告死锁。
Workarounds
-
92% success
select { case v := <-ch: return v case <-time.After(5 * time.Second): return errors.New("timeout") } -
95% success
select { case v := <-ch: return v, nil case <-ctx.Done(): return nil, ctx.Err() }
Dead Ends
Common approaches that don't work:
-
85% fail
Turns a blocking wait into a busy loop that spins CPU at 100%.
-
80% fail
Polling with sleeps adds latency and still misses events under load.