From 1b8826beee9c86b76091931991f037c1410d0ea5 Mon Sep 17 00:00:00 2001 From: fanjiyun Date: Sat, 24 Oct 2020 11:47:53 +0800 Subject: [PATCH] docker stats: fix 'panic: close of closed channel' Signed-off-by: fanjiyun --- pkg/pubsub/publisher.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/pubsub/publisher.go b/pkg/pubsub/publisher.go index 32b2f18925..e53d17d515 100644 --- a/pkg/pubsub/publisher.go +++ b/pkg/pubsub/publisher.go @@ -66,8 +66,11 @@ func (p *Publisher) SubscribeTopicWithBuffer(topic topicFunc, buffer int) chan i // Evict removes the specified subscriber from receiving any more messages. func (p *Publisher) Evict(sub chan interface{}) { p.m.Lock() - delete(p.subscribers, sub) - close(sub) + _, exists := p.subscribers[sub] + if exists { + delete(p.subscribers, sub) + close(sub) + } p.m.Unlock() }