Skip to content

Re-read system nameservers when they change - #222

Open
MarrasFederico wants to merge 1 commit into
CauldronDevelopmentLLC:masterfrom
MarrasFederico:dns-refresh-on-change
Open

MarrasFederico wants to merge 1 commit into
CauldronDevelopmentLLC:masterfrom
MarrasFederico:dns-refresh-on-change

Conversation

@MarrasFederico

@MarrasFederico MarrasFederico commented Nov 14, 2026 •

Copy link
Copy Markdown

Re: FoldingAtHome/fah-client-bastet#337

DNS::Base reads the system nameservers only while its server list is empty. After a network change, such as a VPN disconnecting or reconnecting, it keeps querying the old servers. It moves on only once pump() has dropped each of them after maxFailures failures, and until then it never uses servers that appeared later.

With this change initSystemNameservers() follows the system list. It runs at the top of pump(), still at most once every 5 s, so no Nameserver is on the stack when one is removed. add() is unchanged.

  • Ports are normalized to 53 before comparing, because Windows reports port 0. The list is also sorted and deduplicated.

  • An empty or unchanged list leaves the servers alone, so servers dropped by pump() stay dropped while the network is stable.

  • A changed list is used only once two consecutive reads agree. While a VPN was switching protocol, Windows reported a partial list for a few seconds.

  • On a confirmed change:

    1. servers not in use are added first, including ones dropped on the old network;
    2. servers the system no longer reports are then stopped and removed.

    Requests answered with SHUTDOWN are retried on the new servers in the same pump().

  • Nameservers added by hand are respected as before: if any was added with addNameserver() or CBANG_DNS, the system list is not used.

Testing

Linux, debug build. A test program used fake DNS servers on loopback and a CBANG_RESOLV_CONF file rewritten while it ran.

  • After the list changed, master recovered only once the stale servers had failed maxFailures times, after 70 s. With this change, lookups worked again 10 s after the change.
  • The other cases behave as on master: a stable list, a failing server, a list that differs for a single read, and CBANG_DNS.
  • AddressSanitizer reports no errors.

Windows 11, MSVC x64 debug, NordVPN. Test programs linked against master and against this change ran side by side.

  • VPN stable: both behave the same, with no servers removed or re-added.
  • VPN disconnected: master kept sending every query to the VPN's resolvers, now outside the tunnel. With this change the LAN servers were in use 5 s later.
  • VPN reconnected: the VPN's resolvers were back in use 8 s later.
  • Lookups: applying the new list caused no failed lookups. One lookup failed at the moment the tunnel went down, on master too.

fah-client-bastet builds against this branch with no new warnings, and its unit tests pass.

Known cost: after a change, servers that had been dropped are tried again. Unreachable ones then time out for about a minute, until pump() drops them again. Lookups were not slower in the tests.

The system nameservers were read only while the server list was empty,
so after a network change, e.g. a VPN reconnect, the old servers stayed
in use until each one had failed maxFailures times.

initSystemNameservers() now runs from pump(), still at most once every
five seconds, and follows the system list:

- Ports are normalized to 53 and the list is sorted and deduplicated.
- An empty or unchanged list leaves the servers alone.
- A changed list is used only once two consecutive reads agree.
- Servers not in use are added before stale ones are removed, so
  requests stopped by the removal are retried on the new servers.
- Nameservers added by hand or through CBANG_DNS are left alone.

Re: FoldingAtHome/fah-client-bastet#337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant