Go: panic: close of closed channel (or close of nil channel)
close(ch) was called twice, or on a nil channel.
panic: close of closed channelclose of closed channelpanic: close of nil channelclose of nil channel Meaning
Closing is a one-time signal. Guard it with sync.Once, ensure only one goroutine owns closing, or avoid closing channels used only as data pipes. Closing a nil channel also panics; initialise with make.
Common causes
- Two goroutines closing the same channel
- close in defer plus explicit close
- Repeated shutdown calls
- Nil channel never created
- Library Close called twice
⚡ Quick fix
- Wrap in
sync.Once:once.Do(func(){ close(ch) }) - Assign a single owner for close
- Initialise channels with make
Detailed fix by platform
Go
var once sync.Once; func stop() { once.Do(func() { close(done) }) }
How to diagnose
- Calls — How many closers?
- Nil — Created with make?
- Guard — Once?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Go
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026