From a01f0b4e5eac9e3bb6b5e024f92df15bffe06c24 Mon Sep 17 00:00:00 2001 From: caiweidong Date: Fri, 26 Apr 2019 13:09:20 +0800 Subject: [PATCH] Bugfix: fix channel leak when stop error --- pkg/kubelet/util/pluginwatcher/plugin_watcher.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/kubelet/util/pluginwatcher/plugin_watcher.go b/pkg/kubelet/util/pluginwatcher/plugin_watcher.go index fbe8aa69d4a..f1c6293a144 100644 --- a/pkg/kubelet/util/pluginwatcher/plugin_watcher.go +++ b/pkg/kubelet/util/pluginwatcher/plugin_watcher.go @@ -161,14 +161,17 @@ func (w *Watcher) Stop() error { close(w.stopCh) c := make(chan struct{}) + var once sync.Once + closeFunc := func() { close(c) } go func() { - defer close(c) + defer once.Do(closeFunc) w.wg.Wait() }() select { case <-c: case <-time.After(11 * time.Second): + once.Do(closeFunc) return fmt.Errorf("timeout on stopping watcher") }