Skip to content

Commit 9d2bb68

Browse files
committed
Replace goroutine spawns with nested loops
Signed-off-by: Mikhail Lukianchenko <[email protected]>
1 parent dae7ddd commit 9d2bb68

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

pkg/guestagent/guestagent_linux.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -250,26 +250,27 @@ func (a *agent) Info(ctx context.Context) (*api.Info, error) {
250250
const deltaLimit = 2 * time.Second
251251

252252
func (a *agent) fixSystemTimeSkew() {
253-
ticker := time.NewTicker(10 * time.Second)
254-
defer ticker.Stop()
255-
for now := range ticker.C {
256-
rtc, err := timesync.GetRTCTime()
257-
if err != nil {
258-
logrus.Warnf("fixSystemTimeSkew: lookup error: %s", err.Error())
259-
continue
260-
}
261-
d := rtc.Sub(now)
262-
logrus.Debugf("fixSystemTimeSkew: rtc=%s systime=%s delta=%s",
263-
rtc.Format(time.RFC3339), now.Format(time.RFC3339), d)
264-
if d > deltaLimit || d < -deltaLimit {
265-
err = timesync.SetSystemTime(rtc)
253+
for {
254+
ticker := time.NewTicker(10 * time.Second)
255+
for now := range ticker.C {
256+
rtc, err := timesync.GetRTCTime()
266257
if err != nil {
267-
logrus.Warnf("fixSystemTimeSkew: set system clock error: %s", err.Error())
258+
logrus.Warnf("fixSystemTimeSkew: lookup error: %s", err.Error())
268259
continue
269260
}
270-
logrus.Infof("fixSystemTimeSkew: system time synchronized with rtc")
271-
break
261+
d := rtc.Sub(now)
262+
logrus.Debugf("fixSystemTimeSkew: rtc=%s systime=%s delta=%s",
263+
rtc.Format(time.RFC3339), now.Format(time.RFC3339), d)
264+
if d > deltaLimit || d < -deltaLimit {
265+
err = timesync.SetSystemTime(rtc)
266+
if err != nil {
267+
logrus.Warnf("fixSystemTimeSkew: set system clock error: %s", err.Error())
268+
continue
269+
}
270+
logrus.Infof("fixSystemTimeSkew: system time synchronized with rtc")
271+
break
272+
}
272273
}
274+
ticker.Stop()
273275
}
274-
go a.fixSystemTimeSkew()
275276
}

0 commit comments

Comments
 (0)