Browse Source

prod: drain successes on close just like errors

We kindly drain the errors channel on close so that users who stop reading from
it when calling close (e.g. in a defer) don't hang. We should do the same thing
for the successes channel when AckSuccesses is defined.

May or may not fix the bug reported tangentially at the bottom of
https://github.com/Shopify/sarama/issues/180#issuecomment-63127314
where shutting down with AckSuccesses could be very slow.
Evan Huus 11 years ago
parent
commit
2e6fb8a131
1 changed files with 7 additions and 0 deletions
  1. 7 0
      producer.go

+ 7 - 0
producer.go

@@ -212,6 +212,13 @@ func (p *Producer) Close() error {
 		p.input <- &MessageToSend{flags: shutdown}
 	}()
 
+	if p.config.AckSuccesses {
+		go func() {
+			for _ = range p.successes {
+			}
+		}()
+	}
+
 	var errors ProduceErrors
 	for event := range p.errors {
 		errors = append(errors, event)