From a68454ceeccb4137f26efc0f82c35e4098fea51e Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Tue, 27 Feb 2024 16:15:42 +0100 Subject: [PATCH] Reuse backoff waiting code for errors during GeoIP update. --- hub.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hub.go b/hub.go index d8349c4..301ac08 100644 --- a/hub.go +++ b/hub.go @@ -417,19 +417,20 @@ func (h *Hub) updateGeoDatabase() { } defer h.geoipUpdating.Store(false) - delay := time.Second + backoff, err := NewExponentialBackoff(time.Second, 5*time.Minute) + if err != nil { + log.Printf("Could not create exponential backoff: %s", err) + return + } + for !h.closer.IsClosed() { err := h.geoip.Update() if err == nil { break } - log.Printf("Could not update GeoIP database, will retry later (%s)", err) - time.Sleep(delay) - delay = delay * 2 - if delay > 5*time.Minute { - delay = 5 * time.Minute - } + log.Printf("Could not update GeoIP database, will retry in %s (%s)", backoff.NextWait(), err) + backoff.Wait(context.Background()) } }