Skip to content

Commit

Permalink
tolerate DNS timeouts and handle them more gracefully
Browse files Browse the repository at this point in the history
Potential fix for #54
  • Loading branch information
dlenski committed Jun 9, 2020
1 parent 9b1393e commit fdf9ef2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion vpn_slice/dnspython.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit fdf9ef2

Please sign in to comment.