go runtime_error ai_generated true

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

ID: go/goroutine-leak-no-receiver

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.20 active
1.21 active

Root Cause

A goroutine is stuck sending to a channel with no active receiver, and the main goroutine is waiting for it, causing a deadlock.

generic

中文

一个 goroutine 在向没有活动接收者的通道发送时卡住,主 goroutine 在等待它,导致死锁。

Workarounds

  1. 95% success
    ch := make(chan int); go func() { <-ch }(); ch <- 42
  2. 85% success
    ch := make(chan int, 1); ch <- 42

Dead Ends

Common approaches that don't work:

  1. 75% fail

    If sender sends more than buffer size, it still blocks without receiver.

  2. 90% fail

    Sleep doesn't add a receiver; block remains after sleep.