From 6dcb83feab0f32372b1732ecc2279084ab3d8648 Mon Sep 17 00:00:00 2001 From: Fred Lotter Date: Fri, 16 Aug 2024 09:08:04 +0200 Subject: [PATCH] Review feedback changes 1 --- internals/overlord/overlord.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/internals/overlord/overlord.go b/internals/overlord/overlord.go index b2a09d65..f00c3d27 100644 --- a/internals/overlord/overlord.go +++ b/internals/overlord/overlord.go @@ -328,19 +328,14 @@ func (o *Overlord) ensureTimerSetup() { o.pruneTicker = time.NewTicker(pruneInterval) } -func (o *Overlord) ensureTimerStopClearChannel() { +func (o *Overlord) ensureTimerStop() { o.ensureLock.Lock() defer o.ensureLock.Unlock() - // The Go v1.x timer implementation does not guarantee that a Reset - // clears the channel. The documented proposal is to call stop and - // manually clear the channel if it already expired. This is required - // on loop entry because the timer is started much earlier, and - // managers are now allowed to call state.EnsureBefore() as soon as state - // is available. If the ensure timer expired before loop entry, this code - // ensures the channel is cleared and that only the ensure on entry is - // performed (and not a second ensure as a result of the channel). - // See: https://pkg.go.dev/time#Timer.Reset o.ensureTimer.Stop() + // The Go version < 1.23 timer implementation does not guarantee that a + // Stop clears the channel. The documented proposal is to call stop and + // manually clear the channel if it already expired. + // See: https://pkg.go.dev/time#Timer.Stop select { case <-o.ensureTimer.C: default: @@ -384,10 +379,10 @@ func (o *Overlord) ensureBefore(d time.Duration) { // Loop runs a loop in a goroutine to ensure the current state regularly through StateEngine Ensure. func (o *Overlord) Loop() { o.loopTomb.Go(func() error { - // We are about to perform the first ensure on loop entry. Stop and - // clear the timer channel, so we do not process a spurious second + // We are about to perform the first ensure on loop entry. Stop (and + // clear the timer channel), so we do not process a spurious second // ensure due to a pending timer channel expiry. - o.ensureTimerStopClearChannel() + o.ensureTimerStop() for { // TODO: pass a proper context into Ensure o.ensureTimerReset()