go
runtime_error
ai_generated
true
panic: runtime error: select on nil channel
ID: go/goroutine-select-on-nil-channel
80%Fix Rate
86%Confidence
0Evidence
2025-02-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.19 | active | — | — | — |
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
Using a nil channel in a select statement, which causes a permanent block and potential deadlock.
generic中文
在select语句中使用nil通道,导致永久阻塞和潜在死锁。
Workarounds
-
95% success Initialize channels before use in select
ch := make(chan int); select { case v := <-ch: // use v } -
90% success Check for nil before select
if ch != nil { select { case v := <-ch: // } }
Dead Ends
Common approaches that don't work:
-
Adding default case without fixing nil
80% fail
Default case executes but nil channel still blocks if selected.
-
Using recover() to ignore
90% fail
Does not fix nil channel issue.