From 4e85d42f998f5e3e5f7c49e214c1c2345f7cbe60 Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Tue, 9 Feb 2016 00:11:27 -0800 Subject: [PATCH] fix logging every microsecond when etcd goes down --- pkg/storage/cacher.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/storage/cacher.go b/pkg/storage/cacher.go index 63faf16cbbc..c5bcf2448c6 100644 --- a/pkg/storage/cacher.go +++ b/pkg/storage/cacher.go @@ -171,13 +171,14 @@ func NewCacherFromConfig(config CacherConfig) *Cacher { stopCh := cacher.stopCh cacher.stopWg.Add(1) go func() { + defer cacher.stopWg.Done() wait.Until( func() { if !cacher.isStopped() { cacher.startCaching(stopCh) } - }, 0, stopCh) - cacher.stopWg.Done() + }, time.Second, stopCh, + ) }() return cacher } @@ -197,12 +198,10 @@ func (c *Cacher) startCaching(stopChannel <-chan struct{}) { c.terminateAllWatchers() // Note that since onReplace may be not called due to errors, we explicitly // need to retry it on errors under lock. - for { - if err := c.reflector.ListAndWatch(stopChannel); err != nil { - glog.Errorf("unexpected ListAndWatch error: %v", err) - } else { - break - } + // Also note that startCaching is called in a loop, so there's no need + // to have another loop here. + if err := c.reflector.ListAndWatch(stopChannel); err != nil { + glog.Errorf("unexpected ListAndWatch error: %v", err) } }