go runtime_error ai_generated true

fatal error: all goroutines are asleep - deadlock! (empty select{})

ID: go/select-empty-blocks-forever

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.17 active — — —
1.21 active — — —

Root Cause

An empty select{} blocks forever with no cases. If the main goroutine hits it without other live goroutines, the runtime reports deadlock.

generic

中文

空 select{} 永远阻塞且没有 case。若主 goroutine 在其上阻塞且无其他存活 goroutine,运行时会报告死锁。

Workarounds

  1. 96% success
    sig := make(chan os.Signal, 1)
    signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
    <-sig
  2. 95% success
    <-ctx.Done()

Dead Ends

Common approaches that don't work:

  1. 85% fail

    Busy-spins and consumes 100% CPU; not a real fix for missing shutdown logic.

  2. 95% fail

    The select{} never returns, so the sleep is unreachable.