From 0591a941a7b02cc151eec0e5a88d78f3b443f5e8 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Thu, 6 Feb 2025 19:45:24 +0100 Subject: [PATCH] notifications: do not hog the CPU if there's no L402 token yet --- notifications/manager.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/notifications/manager.go b/notifications/manager.go index 023fbcafd..4dbdc3833 100644 --- a/notifications/manager.go +++ b/notifications/manager.go @@ -149,6 +149,7 @@ func (m *Manager) Run(ctx context.Context) error { waitTime time.Duration backoff time.Duration attempts int + timer = time.NewTimer(0) ) // Start the notification runloop. @@ -156,7 +157,9 @@ func (m *Manager) Run(ctx context.Context) error { // Increase the wait time for the next iteration. backoff = waitTime + time.Duration(attempts)*time.Second waitTime = 0 - timer := time.NewTimer(backoff) + + // Reset the timer with the new backoff time. + timer.Reset(backoff) // Return if the context has been canceled. select { @@ -179,6 +182,10 @@ func (m *Manager) Run(ctx context.Context) error { log.Errorf("Error getting L402 from "+ "the store: %v", err) } + + // Use a default of 1 second wait time to avoid + // hogging the CPU. + waitTime = time.Second continue }