On Sun, Nov 2, 2025 at 6:35 PM Ja kub <[email protected]> wrote: > > "A: Yes, except for one thing. That one thing is a behavior you are almost > surely not depending on, but may have cursed excessively at in the past: > closing a channel twice in Go causes a panic. Closing a channel in Pont never > panics, no matter how many times you close it." > > I love it and never understood why in Go closing a channel more than once > causes a panic. Can someone explain why is that?
Closing a channel is an operation done on the sender side of a channel to signal that no further information will be sent on the channel. If there are multiple goroutines closing the channel, that means that multiple goroutines need to somehow coordinate that there is nothing else to send. If the goroutines do that coordination, it's a fairly minor addition to coordinate which goroutine actually calls close. If the goroutines don't do that goroutine, there is likely a program error, and a panic calls attention to that. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXO2zmEPPa2cr9k1Y%3DRjyF7b9-4d8dFwV_EOY_%3Di8KN2A%40mail.gmail.com.
