go runtime_error ai_generated true

fatal error: all goroutines are asleep - deadlock! (buffered channel full)

ID: go/goroutine-channel-buffer-overflow

Also available as: JSON · Markdown · 中文
80%Fix Rate
83%Confidence
0Evidence
2025-02-28First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.0 active
1.21 active

Root Cause

Sending to a buffered channel that is full, with no receiver ready, causing sender to block indefinitely.

generic

中文

向已满的缓冲通道发送数据,没有接收者就绪,导致发送者无限阻塞。

Workarounds

  1. 90% success Ensure sufficient consumer goroutines to drain channel
    ch := make(chan int, 10)
    go func() {
        for val := range ch {
            // consume
        }
    }()
    for i := 0; i < 20; i++ {
        ch <- i
    }
  2. 85% success Use unbuffered channel with proper synchronization
    ch := make(chan int)
    go func() {
        for val := range ch {
            // consume
        }
    }()
    ch <- 42 // blocks until receiver ready

Dead Ends

Common approaches that don't work:

  1. Increasing buffer size arbitrarily 70% fail

    Only delays the problem; if consumers are missing, buffer will fill again.

  2. Using non-blocking send with select default 60% fail

    Default case drops data; may lose messages.