vibe-d / vibe.d

Official vibe.d development
MIT License
1.15k stars 284 forks source link

DNS resolution only considers one name server #1612

Open mihails-strasuns opened 8 years ago

mihails-strasuns commented 8 years ago

Noticed this by accident. I have two DNS servers configured in my resolv.conf:

$ cat /etc/resolv.conf
# Generated by resolvconf
nameserver <internal>
nameserver <fallback>

First one is local network cache, second provides fallback if first goes down or misses name sync. At some point I have stopped internal DNS cache during some debugging and my vibe.d based scripts started to fail like this:

object.Exception@../../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/core/drivers/libevent2.d(270): Failed to lookup host 'dlang.org': non-recoverable failure in name resolution

Changing first resolv.conf entry to refer to working DNS server fixed the issue.

s-ludwig commented 8 years ago

I'm not sure if this is a libevent bug or if I'm doing something wrong here. The docs say that evdns_init() parses resolv.conf, and multiple name servers are supported, too, so in theory this should work. In case this isn't fixable within vibe.d, the new vibe-core module will be usable as a replacement to vibe:core soon and uses the system provided getaddrinfo(_a), which should work as expected.

mihails-strasuns commented 8 years ago

No problem, this is not really an issue for me, only reporting in case someone else gets confused by it again.

MartinNowak commented 7 years ago

the new vibe-core module will be usable as a replacement to vibe:core soon and uses the system provided getaddrinfo(_a)

Really using a synchronous DNS resolver? I see, there is getaddrinfo_a(3).

MartinNowak commented 7 years ago

Just debugged libevent, it does parse all nameservers. It even already parses the host file https://github.com/libevent/libevent/blob/release-2.0.16-stable/evdns.c#L3509-L3514.

MartinNowak commented 7 years ago

Indeed seems to be a evdns/libevent bug it doesn't query the DNS servers in order, but tries to query them in round robin order, which might lead to unexpected name resolution errors. https://github.com/libevent/libevent/blob/3821cca1a637f4da4099c9343e7326da00f6981c/evdns.c#L715 Workaround is to fix your resolv.conf setup to have all nameservers return the same responses, or use a local dnsmasq to forward the searches.