Why This Happens
A nil channel blocks forever on both send and receive operations. It never panics directly but causes a deadlock because no goroutine can make progress. This happens when you declare a channel variable but forget to call make(chan T) on it.
The Problem
func main() {
var ch chan int
ch <- 42 // blocks forever on nil channel
}The Fix
func main() {
ch := make(chan int, 1)
ch <- 42
fmt.Println(<-ch)
}Step-by-Step Fix
- 1
Identify the nil channel
Check the deadlock stack trace and find the channel operation. Inspect the channel variable to see if it is nil.
- 2
Trace the declaration
Find where the channel was declared and check if make() was called on it.
- 3
Initialize with make
Use make(chan T) or make(chan T, bufferSize) to properly initialize the channel.
Got the actual stack trace?
Paste it into our free AI explainer to get the cause and the fix for your specific case — no signup, nothing to install.
Explain my errorBugsly catches this automatically
Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.
Try Bugsly free