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

Also available as: JSON · Markdown · 中文
80%Fix Rate
89%Confidence
0Evidence
2024-09-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 92% success
    select {
    case v := <-ch:
        return v
    case <-time.After(5 * time.Second):
        return errors.New("timeout")
    }
  2. 95% success
    select {
    case v := <-ch:
        return v, nil
    case <-ctx.Done():
        return nil, ctx.Err()
    }

Dead Ends

Common approaches that don't work:

  1. 85% fail

    Turns a blocking wait into a busy loop that spins CPU at 100%.

  2. 80% fail

    Polling with sleeps adds latency and still misses events under load.