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

**Code:** `panic: close of closed channel` · **Category:** Go · **Seen on:** Go

`close(ch)` was called twice, or on a 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

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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/go/close-of-closed-channel)
