From a1ad496b3176c048d30e1a7b6b264fd0953a0158 Mon Sep 17 00:00:00 2001 From: Dimitrij Denissenko Date: Sun, 29 Apr 2018 11:55:36 +0100 Subject: [PATCH] Make PartitionConsumer.Close idempotent --- consumer.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/consumer.go b/consumer.go index be4e6d4a3..96226ac5b 100644 --- a/consumer.go +++ b/consumer.go @@ -310,6 +310,7 @@ type partitionConsumer struct { trigger, dying chan none responseResult error + closeOnce sync.Once fetchSize int32 offset int64 @@ -412,7 +413,9 @@ func (child *partitionConsumer) AsyncClose() { // the dispatcher to exit its loop, which removes it from the consumer then closes its 'messages' and // 'errors' channel (alternatively, if the child is already at the dispatcher for some reason, that will // also just close itself) - close(child.dying) + child.closeOnce.Do(func() { + close(child.dying) + }) } func (child *partitionConsumer) Close() error {