All active goroutines are blocked waiting for channels or locks that will never unblock.
Go's runtime monitors goroutine scheduling. When every goroutine in the program becomes permanently blocked on channel sends/receives or mutex locks, Go terminates the process with a deadlock error.
Common causes: sending to an unbuffered channel without a receiver goroutine ready, reading from a channel that no goroutine writes to, or forgetting `wg.Done()` when using `sync.WaitGroup`.
1package main2 3func main() {4 ch := make(chan int) // Unbuffered channel5 ch <- 42 // Blocks forever waiting for receiver!6 println(<-ch)7}1package main2 3func main() {4 // Fix 1: Receive in a separate goroutine or send in one5 ch := make(chan int)6 go func() {7 ch <- 428 }()9 println(<-ch) // 4210 11 // Fix 2: Use a buffered channel if async queueing is appropriate12 bufCh := make(chan int, 1)13 bufCh <- 9914 println(<-bufCh) // 9915}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
Unbuffered channels require both a sender and a receiver to be ready simultaneously. Sending `ch <- 42` blocks the main goroutine, but there are no other goroutines to receive it, resulting in a deadlock.