go runtime_error ai_generated true

fatal error: all goroutines are asleep - deadlock! (goroutine 1 [chan receive])

ID: go/goroutine-leak-no-sender

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.20 active
1.21 active

Root Cause

A goroutine is blocked receiving from a channel that never receives data, with no active sender.

generic

中文

一个 goroutine 在从一个永远不会接收数据的通道接收时阻塞,没有活动的发送者。

Workarounds

  1. 95% success
    ch := make(chan int); go func() { ch <- 42 }(); val := <-ch
  2. 85% success
    select { case val := <-ch: case <-time.After(time.Second): }

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Receive from closed channel returns zero value immediately, not blocking, but may not be desired.

  2. 90% fail

    Sleep doesn't create a sender; still blocks forever.