go runtime_error ai_generated true

fatal error: all goroutines are asleep - deadlock! (select with no cases)

ID: go/select-empty-deadlock

Also available as: JSON · Markdown · 中文
80%Fix Rate
90%Confidence
0Evidence
2024-04-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.0+ active — — —

Root Cause

A select statement with no cases blocks forever, and if all goroutines are blocked, the runtime detects deadlock.

generic

中文

select 语句没有任何 case,会永远阻塞,如果所有 goroutine 都阻塞,运行时会检测到死锁。

Workarounds

  1. 98% success
    select {
    case <-ch:
        // handle
    }
  2. 95% success
    select {
    case <-done:
        return
    case <-ch:
        // handle
    }

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Default case may cause busy loop and still not solve logical deadlock

  2. 90% fail

    Sleep does not help; select with no cases is invalid