From 907aa9b06515877f43a20a4b6ef184c9044774b5 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Thu, 28 Dec 2023 12:04:58 -0700 Subject: [PATCH] addons auto-pause: Revert cleanup on ticker allocations --- cmd/auto-pause/auto-pause.go | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/cmd/auto-pause/auto-pause.go b/cmd/auto-pause/auto-pause.go index 6c80d530fc..17d3a998fe 100644 --- a/cmd/auto-pause/auto-pause.go +++ b/cmd/auto-pause/auto-pause.go @@ -48,38 +48,21 @@ func main() { // TODO: #10595 make this configurable const interval = time.Minute * 1 - // Check if interval is greater than 0 so NewTicker does not panic. - if interval <= 0 { - exit.Message(reason.Usage, "Auto-pause interval must be greater than 0,"+ - " not current value of {{.interval}}", out.V{"interval": interval.String()}) - } - tickerChannel := time.NewTicker(interval) - // Check current state alreadyPaused() // channel for incoming messages go func() { for { + // On each iteration new timer is created select { - case <-tickerChannel.C: + // TODO: #10596 make it memory-leak proof + case <-time.After(interval): runPause() case <-unpauseRequests: fmt.Printf("Got request\n") if runtimePaused { runUnpause() - - // Reset once cluster has been unpaused. - tickerChannel.Reset(interval) - - // Avoid race where tick happens before Reset call and after unPause. - for { - select { - case <-tickerChannel.C: - default: - break - } - } } done <- struct{}{}