diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | dns/resolver.py | 17 |
2 files changed, 22 insertions, 0 deletions
@@ -1,3 +1,8 @@ +2012-04-08 Bob Halley <halley@dnspython.org> + + * dns/resolver.py (Resolver.query): Switch to TCP when a UDP + response is truncated. Handle nameservers that serve on UDP + but not TCP. 2012-04-07 Bob Halley <halley@dnspython.org> diff --git a/dns/resolver.py b/dns/resolver.py index 90f95e8..2f56c7d 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -23,6 +23,7 @@ import sys import time import dns.exception +import dns.flags import dns.ipv4 import dns.ipv6 import dns.message @@ -778,6 +779,12 @@ class Resolver(object): response = dns.query.udp(request, nameserver, timeout, self.port, source=source) + if response.flags & dns.flags.TC: + # Response truncated; retry with TCP. + timeout = self._compute_timeout(start) + response = dns.query.tcp(request, nameserver, + timeout, self.port, + source=source) except (socket.error, dns.exception.Timeout): # # Communication failure or timeout. Go to the @@ -800,6 +807,16 @@ class Resolver(object): nameservers.remove(nameserver) response = None continue + except EOFError: + # + # We're using TCP and they hung up on us. + # Probably they don't support TCP (though + # they're supposed to!). Take it out of the + # mix and continue. + # + nameservers.remove(nameserver) + response = None + continue rcode = response.rcode() if rcode == dns.rcode.NOERROR or \ rcode == dns.rcode.NXDOMAIN: |