From 95950429d7ade5c40f2b134535bb3fd49442ef6b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Va=C5=A1ek?= <david.vasek@nic.cz>
Date: Fri, 31 Dec 2021 16:50:26 +0100
Subject: [PATCH] refresh: use exponential retry backoff with base 2 rather
 than 3

By using the cumulative time since the zone expiration (instead of the last
time interval) we achieve an approximation of exponential retry backoff with
base 2 (rather than with base 3, as it was until now). Now, with every retry attempt,
the interval between refreshes only doubles (with up to 30 second jitter).

This change helps avoid excessive waiting for a refresh when a few early attempts
fail.
---
 src/knot/events/handlers/refresh.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/knot/events/handlers/refresh.c b/src/knot/events/handlers/refresh.c
index 38cb9a2303..571ee8162d 100644
--- a/src/knot/events/handlers/refresh.c
+++ b/src/knot/events/handlers/refresh.c
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2021 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2022 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -139,14 +139,13 @@ static time_t bootstrap_next(const zone_timers_t *timers)
 {
 	time_t expired_at = timers->last_refresh + timers->soa_expire;
 
-	// previous interval
+	// Time since the zone expiration.
+	// The new interval is double of the previous one (an exponential backoff).
 	time_t interval = timers->next_refresh - expired_at;
 	if (interval < 0) {
 		interval = 0;
 	}
 
-	// exponential backoff
-	interval *= 2;
 	if (interval > BOOTSTRAP_MAXTIME) {
 		interval = BOOTSTRAP_MAXTIME;
 	}
-- 
GitLab