Attempting to close a Go channel that has already been closed.
Go channels can only be closed once. Closing a channel that is already closed will trigger an unrecoverable runtime panic.
Multiple goroutines attempting to close the same channel in cleanup blocks, or executing double close on a channel.
1package main2 3func main() {4 ch := make(chan int)5 close(ch)6 close(ch) // Panic: close of closed channel7}1package main2 3import "sync"4 5func main() {6 ch := make(chan int)7 var once sync.Once8 9 // Fix: Use sync.Once to ensure channel is only closed once10 safeClose := func() {11 once.Do(func() {12 close(ch)13 })14 }15 16 safeClose()17 safeClose() // Safe: sync.Once guarantees close is only called once18}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
The channel is already closed on the first call to close(ch). The second call attempts to close it again, violating Go's channel safety state machine and raising a panic.