From 44b5375bb470143defb627b509410f10749722b4 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 30 Aug 2022 16:12:38 +0200 Subject: [PATCH] Show update failed notification only after some failed tries --- updates/main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/updates/main.go b/updates/main.go index b5586a43..434256cf 100644 --- a/updates/main.go +++ b/updates/main.go @@ -5,6 +5,7 @@ import ( "flag" "fmt" "runtime" + "sync/atomic" "time" "github.com/safing/portbase/database" @@ -209,6 +210,8 @@ func DisableUpdateSchedule() error { return nil } +var updateFailedCnt = new(atomic.Int32) + func checkForUpdates(ctx context.Context) (err error) { if !forceUpdate.SetToIf(true, false) && !enableUpdates() { log.Warningf("updates: automatic updates are disabled") @@ -216,7 +219,9 @@ func checkForUpdates(ctx context.Context) (err error) { } defer func() { + // Resolve any error and and send succes notification. if err == nil { + updateFailedCnt.Store(0) log.Infof("updates: successfully checked for updates") module.Resolve(updateFailed) notifications.Notify(¬ifications.Notification{ @@ -232,7 +237,14 @@ func checkForUpdates(ctx context.Context) (err error) { }, }, }) - } else { + return + } + + // Log error in any case. + log.Errorf("updates: check failed: %s", err) + + // Do not alert user if update failed for only a few times. + if updateFailedCnt.Add(1) > 3 { notifications.NotifyWarn( updateFailed, "Update Check Failed",