Skip to content

Commit

Permalink
Klibs: syslog: improve DNS resolution of syslog server name
Browse files Browse the repository at this point in the history
In case of failure to resolve the syslog server name, using a pure
exponential backoff delay for retrying DNS resolution can cause
logs to be shipped long after a previousy unresolvable server
became resolvable. This commit puts a 1-minute limit to the backoff
delay.
The current code stops resolving the syslog server name after a
successful resolution, and this can cause issues if the server IP
address changes. To solve this problem, the dns_gethostbyname()
function is now called even after the server name has been
successfully resolved, so that when the cached DNS entry expires a
new DNS request will be sent.
  • Loading branch information
francescolavra committed Feb 2, 2022
1 parent 52d6a0d commit f970a8a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions klib/syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static void syslog_dns_failure(void)
{
if (syslog.dns_backoff == 0)
syslog.dns_backoff = seconds(1);
else
else if (syslog.dns_backoff < seconds(60))
syslog.dns_backoff *= 2;
syslog.dns_req_next = kern_now(CLOCK_ID_MONOTONIC) + syslog.dns_backoff;
}
Expand Down Expand Up @@ -239,10 +239,9 @@ static void syslog_set_hdr_len(void)

static void syslog_udp_flush(void)
{
if (ip_addr_isany_val(syslog.server_ip)) {
syslog_server_resolve();
syslog_server_resolve();
if (ip_addr_isany_val(syslog.server_ip))
return;
}
if (!syslog.hdr_len) {
syslog_set_hdr_len();
if (!syslog.hdr_len)
Expand Down

0 comments on commit f970a8a

Please sign in to comment.