Description
DNSJava v3.4.1.
When a network change is detected, our application calls ResolverConfig.refresh()
. However, this does not clear out the old servers, only adds new ones. This is a problem if disconnecting from a VPN, because the VPN's DNS servers are still active but no longer reachable, resulting in a lot of failed DNS queries.
Technical analysis
ResolverConfig
class contains a static list of ResolverConfigProviders
private static List<ResolverConfigProvider> configProviders;
The objects in this list are populated by checkInitialized
and then never changed unless setConfigProviders
is called.
Each ResolverConfigProvider
contains an initialize
method which invokes BaseResolverConfigProvider.addNameserver
to add servers to the list, but has no means of clearing the list first.
ResolverConfig.refresh()
calls ResolverConfig
constructor which runs initialize()
on each provider, but that doesn't clear out the previous name servers or search paths. So, new ones are added on the end of the lists, but old ones are retained at the start of the lists.