From d91f16374b9ace86b6916a129ca405f3b05db561 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Mon, 4 May 2020 08:20:22 -0700 Subject: [PATCH] Fix [Issue #416], EAI_SYSTEM not defined on Windows. --- dns/resolver.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dns/resolver.py b/dns/resolver.py index e6f145b7..456bb6c4 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -1234,7 +1234,12 @@ def _getaddrinfo(host=None, service=None, family=socket.AF_UNSPEC, socktype=0, # Not implemented. We raise a gaierror as opposed to a # NotImplementedError as it helps callers handle errors more # appropriately. [Issue #316] - raise socket.gaierror(socket.EAI_SYSTEM) + # + # We raise EAI_FAIL as opposed to EAI_SYSTEM because there is + # no EAI_SYSTEM on Windows [Issue #416]. We didn't go for + # EAI_BADFLAGS as the flags aren't bad, we just don't + # implement them. + raise socket.gaierror(socket.EAI_FAIL) if host is None and service is None: raise socket.gaierror(socket.EAI_NONAME) v6addrs = [] @@ -1274,7 +1279,10 @@ def _getaddrinfo(host=None, service=None, family=socket.AF_UNSPEC, socktype=0, except dns.resolver.NXDOMAIN: raise socket.gaierror(socket.EAI_NONAME) except Exception: - raise socket.gaierror(socket.EAI_SYSTEM) + # We raise EAI_AGAIN here as the failure may be temporary + # (e.g. a timeout) and EAI_SYSTEM isn't defined on Windows. + # [Issue #416] + raise socket.gaierror(socket.EAI_AGAIN) port = None try: # Is it a port literal? -- 2.47.3