fix logging every microsecond when etcd goes down

pull/6/head
Daniel Smith 2016-02-09 00:11:27 -08:00
parent c75e344b47
commit 4e85d42f99
1 changed files with 7 additions and 8 deletions

View File

@ -171,13 +171,14 @@ func NewCacherFromConfig(config CacherConfig) *Cacher {
stopCh := cacher.stopCh stopCh := cacher.stopCh
cacher.stopWg.Add(1) cacher.stopWg.Add(1)
go func() { go func() {
defer cacher.stopWg.Done()
wait.Until( wait.Until(
func() { func() {
if !cacher.isStopped() { if !cacher.isStopped() {
cacher.startCaching(stopCh) cacher.startCaching(stopCh)
} }
}, 0, stopCh) }, time.Second, stopCh,
cacher.stopWg.Done() )
}() }()
return cacher return cacher
} }
@ -197,12 +198,10 @@ func (c *Cacher) startCaching(stopChannel <-chan struct{}) {
c.terminateAllWatchers() c.terminateAllWatchers()
// Note that since onReplace may be not called due to errors, we explicitly // Note that since onReplace may be not called due to errors, we explicitly
// need to retry it on errors under lock. // need to retry it on errors under lock.
for { // 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 { if err := c.reflector.ListAndWatch(stopChannel); err != nil {
glog.Errorf("unexpected ListAndWatch error: %v", err) glog.Errorf("unexpected ListAndWatch error: %v", err)
} else {
break
}
} }
} }