Skip to content
Preptima
mediumConceptCodingDesignMidSenior

Several producers write to one channel and one consumer reads it. Who closes the channel?

In Go, the sender closes a channel when no more values will be sent; receivers do not close it just because they are done. Multiple senders need coordination so close happens exactly once after all sends finish. Use this channels answer to show the decision, trade-off, and evidence rather than a memorised definition. It also connects goroutines to the point an interviewer is testing.

4 min readUpdated 2026-08-15

Answer

Short answer

The goroutine that owns sending is responsible for closing the channel. With many producers, use a WaitGroup or coordinator to close after all producers exit, and use context cancellation when receivers stop early.

Was this answer helpful?

Likely follow-ups

  • What happens if a second goroutine closes the same channel?
  • How do you signal to the producers that the consumer has given up?
  • Why can the receiver not simply close when it has what it needs?
  • What does the two-value receive form tell you that the one-value form does not?

Related questions

Further reading

Related Topics