From fdf9ef2bcae634cbadace905df569f17b528f7b0 Mon Sep 17 00:00:00 2001 From: Daniel Lenski Date: Tue, 9 Jun 2020 11:01:09 -0700 Subject: [PATCH] tolerate DNS timeouts and handle them more gracefully Potential fix for #54 --- vpn_slice/dnspython.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vpn_slice/dnspython.py b/vpn_slice/dnspython.py index 707abcd..91463d1 100644 --- a/vpn_slice/dnspython.py +++ b/vpn_slice/dnspython.py @@ -1,5 +1,6 @@ +from sys import stderr from ipaddress import ip_address -from dns.resolver import Resolver, NXDOMAIN, NoAnswer +from dns.resolver import Resolver, NXDOMAIN, NoAnswer, Timeout from dns.name import root, from_text from .provider import DNSProvider @@ -31,9 +32,15 @@ def lookup_host(self, hostname, keep_going=True): for rectype in self.rectypes: try: + # print("Issuing query for hostname %r, rectype %r, source %r, search_domains %r, nameservers %r" % ( + # hostname, rectype, source, self.resolver.search_domains, self.resolver.nameservers), file=stderr) a = self.resolver.query(hostname, rectype, source=str(source)) + print("Got results: %r" % list(a), file=stderr) except (NXDOMAIN, NoAnswer): pass + except Timeout: + # No point in retrying with a different rectype if these DNS server(s) are not responding + break else: result.update(ip_address(r.address) for r in a) if result and not keep_going: