timesync: increase retry interval more slowly

The new retry intervals are [15, 20, 26, 34, 45, 60, 80, 106, 141, 188, 250,
333, 360, ...]. This should allow graceful response if a transient network
failure is encountered. Growth is exponential, but with a small power and
capped to a non-too-large value so that we resynchronize within a few minutes
after network is restored. I made the minimum 15 s to make sure that we never
send packets more often than that.

Fixes #16492.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-07-30 15:15:11 +02:00
parent 94ec163ad2
commit 5919bd3df3
2 changed files with 7 additions and 5 deletions
+4 -5
View File
@@ -137,11 +137,10 @@ static int manager_send_request(Manager *m) {
}
/* re-arm timer with increasing timeout, in case the packets never arrive back */
if (m->retry_interval > 0) {
if (m->retry_interval < m->poll_interval_max_usec)
m->retry_interval *= 2;
} else
m->retry_interval = m->poll_interval_min_usec;
if (m->retry_interval == 0)
m->retry_interval = NTP_RETRY_INTERVAL_MIN_USEC;
else
m->retry_interval = MIN(m->retry_interval * 4/3, NTP_RETRY_INTERVAL_MAX_USEC);
r = manager_arm_timer(m, m->retry_interval);
if (r < 0)
+3
View File
@@ -24,6 +24,9 @@ typedef struct Manager Manager;
#define NTP_POLL_INTERVAL_MIN_USEC (32 * USEC_PER_SEC)
#define NTP_POLL_INTERVAL_MAX_USEC (2048 * USEC_PER_SEC)
#define NTP_RETRY_INTERVAL_MIN_USEC (15 * USEC_PER_SEC)
#define NTP_RETRY_INTERVAL_MAX_USEC (6 * 60 * USEC_PER_SEC) /* 6 minutes */
struct Manager {
sd_bus *bus;
sd_event *event;