go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (select with no cases)
ID: go/select-no-case-ready
80%Fix Rate
87%Confidence
0Evidence
2024-05-30First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0 | active | — | — | — |
| 1.21 | active | — | — | — |
Root Cause
A select statement has no case that is ready, and no default, causing the goroutine to block forever.
generic中文
select语句没有任何case就绪,也没有default,导致goroutine永久阻塞。
Workarounds
-
90% success
Ensure at least one channel in the select will eventually receive or send. Use context or done channels.
-
85% success
Include a default case to handle the situation when no channel is ready.
Dead Ends
Common approaches that don't work:
-
60% fail
Adding default changes the semantics; it may cause busy looping.
-
80% fail
Sleep does not guarantee that channels will become ready; it just delays.
-
70% fail
This may break the logic and cause other issues.