Unbuffered Channel Deadlock (ARCH5035)
Key go.async.channel-deadlock · Severity warning · Category async
Sending on an unbuffered channel with no concurrent receiver - or receiving with no sender in the same goroutine - blocks forever. This pattern produces a deadlock that can crash the whole program.
Incorrect
Section titled “Incorrect”func Compute() int { ch := make(chan int) ch <- 42 // no receiver, blocks forever return <-ch}Correct
Section titled “Correct”func Compute() int { ch := make(chan int) go func() { ch <- 42 // sent on a separate goroutine }() return <-ch}Move the send into a separate goroutine or make the channel buffered.