From 991674380b7773d73afaeafeac6242bf3b6e6001 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 25 Oct 2016 11:20:35 +0900 Subject: [PATCH] Fix resync goroutine leak in ListAndWatch Previously, we had no way to stop resync goroutine when ListAndWatch returned. goroutine leaked every time ListAndWatch returned, for example, with error. This commit adds another channel to signal that resync goroutine should exit when ListAndWatch returns. --- pkg/client/cache/reflector.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/client/cache/reflector.go b/pkg/client/cache/reflector.go index 8c8aee3a7b0..785cab22a36 100644 --- a/pkg/client/cache/reflector.go +++ b/pkg/client/cache/reflector.go @@ -259,12 +259,16 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error { r.setLastSyncResourceVersion(resourceVersion) resyncerrc := make(chan error, 1) + cancelCh := make(chan struct{}) + defer close(cancelCh) go func() { for { select { case <-resyncCh: case <-stopCh: return + case <-cancelCh: + return } glog.V(4).Infof("%s: forcing resync", r.name) if err := r.store.Resync(); err != nil {