go runtime_error ai_generated true

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

ID: go/select-no-case-ready

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-05-30First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 90% success
    Ensure at least one channel in the select will eventually receive or send. Use context or done channels.
  2. 85% success
    Include a default case to handle the situation when no channel is ready.

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Adding default changes the semantics; it may cause busy looping.

  2. 80% fail

    Sleep does not guarantee that channels will become ready; it just delays.

  3. 70% fail

    This may break the logic and cause other issues.