I have a VM running Debian Wheezy on which some hostname lookups take several seconds to complete, even though the resolver replies immediately. Strangely, lookups with getaddrinfo()
are affected, but gethostbyname()
is not.
I've switched to the Google resolvers to exclude the possibility that the local ones are broken, so my /etc/resolv.conf
looks like:
search my-domain.com
nameserver 8.8.4.4
nameserver 8.8.8.8
My nsswitch.conf
has the line:
hosts: files dns
and my /etc/hosts
doesn't contain anything unusual.
If I try telnet webserver 80
, it hangs for several seconds before getting a name resolution. An ltrace
output [1] shows that the hang is in a getaddrinfo()
call:
getaddrinfo("ifconfig.me", "telnet", { AI_CANONNAME, 0, SOCK_STREAM, 0, 0, NULL, '\000', NULL }, 0x7fffb4ffc160) = 0 <5.020621>
However, tcpdump
reveals that the nameserver replied immediately, and it was only on the second reply that telnet
unblocked. The replies look identical:
05:52:58.609731 IP 192.168.1.75.43017 > 8.8.4.4.53: 54755+ A? ifconfig.me. (29)
05:52:58.609786 IP 192.168.1.75.43017 > 8.8.4.4.53: 26090+ AAAA? ifconfig.me. (29)
05:52:58.612188 IP 8.8.4.4.53 > 192.168.1.75.43017: 54755 4/0/0 A 219.94.235.40, A 133.242.129.236, A 49.212.149.105, A 49.212.202.172 (93)
[...five second pause...]
05:53:03.613811 IP 192.168.1.75.43017 > 8.8.4.4.53: 54755+ A? ifconfig.me. (29)
05:53:03.616424 IP 8.8.4.4.53 > 192.168.1.75.43017: 54755 4/0/0 A 219.94.235.40, A 133.242.129.236, A 49.212.149.105, A 49.212.202.172 (93)
05:53:03.616547 IP 192.168.1.75.43017 > 8.8.4.4.53: 26090+ AAAA? ifconfig.me. (29)
05:53:03.618907 IP 8.8.4.4.53 > 192.168.1.75.43017: 26090 0/1/0 (76)
I've checked host firewall logs and nothing on port 53 is being blocked.
What is causing the first DNS reply to be ignored?
[1] I've added a couple of lines to my ltrace.conf
so I can see inside the addrinfo
struct.