panic: close of closed channel Go Origin: Application & API Last updated 4 Nov 2026

Go: panic: close of closed channel (or close of nil channel)

close(ch) was called twice, or on a nil channel.

Exact message you may see panic: close of closed channelclose of closed channelpanic: close of nil channelclose of nil channel
Seen on: Go

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

  1. Wrap in sync.Once : once.Do(func(){ close(ch) })
  2. Assign a single owner for close
  3. Initialise channels with make

Detailed fix by platform

Go

  1. var once sync.Once; func stop() { once.Do(func() { close(done) }) }

How to diagnose

  1. Calls — How many closers?
  2. Nil — Created with make?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

all goroutines are asleep - deadlock — Go: fatal error: all goroutines are asleep - deadlock! (Go)all goroutines are as…fatal error: concurrent map read and map write — Go: fatal error: concurrent map read and map write (Go)fatal error: concurre…fatal error: concurrent map writes — Go: fatal error: concurrent map writes (Go)fatal error: concurre…listen tcp :8080: bind: address already in use — Go: listen tcp :8080: bind: address already in use (Go)listen tcp :8080: bin…panic: send on closed channel — Go: panic: send on closed channel (Go)panic: send on closed…panic: sync: negative WaitGroup counter — Go: panic: sync: negative WaitGroup counter (Go)panic: sync: negative…WARNING: DATA RACE — Go: WARNING: DATA RACE — Write at 0x00c0000 by goroutine 7: / Previous read at ... by goroutine 6 (Go)WARNING: DATA RACEpanic: cl…

Explore the map of this error Full error map →

🧠 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.