go concurrency_error ai_generated true

fatal error: all goroutines are asleep - deadlock!

ID: go/channel-deadlock

Also available as: JSON · Markdown
88%Fix Rate
90%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1 active
1 active

Root Cause

All goroutines blocked waiting on channels. No goroutine can make progress.

generic

Workarounds

  1. 92% success Ensure every channel send has a corresponding receive (and vice versa)
    and vice versa

    Sources: https://go.dev/doc/effective_go#channels

  2. 88% success Use select with default case for non-blocking channel operations
    select {
    case msg := <-ch:
        handle(msg)
    default:
        // don't block
    }

    Sources: https://go.dev/ref/spec#Select_statements

  3. 85% success Close channels when done sending: close(ch)
    close(ch)

    Sources: https://go.dev/ref/spec#Close

Dead Ends

Common approaches that don't work:

  1. Use buffered channels with large buffer 65% fail

    Large buffers just delay the deadlock

Error Chain

Leads to: