Replace calls to time.After with time.NewTimer for explicit stopping

This commit is contained in:
Daniel Smith
2015-05-04 14:29:33 -07:00
parent 838b59cb4d
commit 16a6fb8ef7
6 changed files with 48 additions and 18 deletions

View File

@@ -366,16 +366,16 @@ const syncInterval = 5 * time.Second
// SyncLoop runs periodic work. This is expected to run as a goroutine or as the main loop of the app. It does not return.
func (proxier *Proxier) SyncLoop() {
t := time.NewTicker(syncInterval)
defer t.Stop()
for {
select {
case <-time.After(syncInterval):
glog.V(3).Infof("Periodic sync")
if err := iptablesInit(proxier.iptables); err != nil {
glog.Errorf("Failed to ensure iptables: %v", err)
}
proxier.ensurePortals()
proxier.cleanupStaleStickySessions()
<-t.C
glog.V(3).Infof("Periodic sync")
if err := iptablesInit(proxier.iptables); err != nil {
glog.Errorf("Failed to ensure iptables: %v", err)
}
proxier.ensurePortals()
proxier.cleanupStaleStickySessions()
}
}