Fix dns resolution without aiodns
(use loop.getaddrinfo instead of the blocking version)
This commit is contained in:
parent
dbd8115557
commit
8ac0ecdf40
1 changed files with 8 additions and 4 deletions
|
@ -177,9 +177,11 @@ def get_A(host, resolver=None, use_aiodns=True):
|
||||||
# If not using aiodns, attempt lookup using the OS level
|
# If not using aiodns, attempt lookup using the OS level
|
||||||
# getaddrinfo() method.
|
# getaddrinfo() method.
|
||||||
if resolver is None or not use_aiodns:
|
if resolver is None or not use_aiodns:
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
try:
|
try:
|
||||||
recs = socket.getaddrinfo(host, None, socket.AF_INET,
|
recs = yield from loop.getaddrinfo(host, None,
|
||||||
socket.SOCK_STREAM)
|
family=socket.AF_INET,
|
||||||
|
type=socket.SOCK_STREAM)
|
||||||
return [rec[4][0] for rec in recs]
|
return [rec[4][0] for rec in recs]
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
log.debug("DNS: Error retrieving A address info for %s." % host)
|
log.debug("DNS: Error retrieving A address info for %s." % host)
|
||||||
|
@ -222,9 +224,11 @@ def get_AAAA(host, resolver=None, use_aiodns=True):
|
||||||
if not socket.has_ipv6:
|
if not socket.has_ipv6:
|
||||||
log.debug("DNS: Unable to query %s for AAAA records: IPv6 is not supported", host)
|
log.debug("DNS: Unable to query %s for AAAA records: IPv6 is not supported", host)
|
||||||
return []
|
return []
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
try:
|
try:
|
||||||
recs = socket.getaddrinfo(host, None, socket.AF_INET6,
|
recs = yield from loop.getaddrinfo(host, None,
|
||||||
socket.SOCK_STREAM)
|
family=socket.AF_INET6,
|
||||||
|
type=socket.SOCK_STREAM)
|
||||||
return [rec[4][0] for rec in recs]
|
return [rec[4][0] for rec in recs]
|
||||||
except (OSError, socket.gaierror):
|
except (OSError, socket.gaierror):
|
||||||
log.debug("DNS: Error retreiving AAAA address " + \
|
log.debug("DNS: Error retreiving AAAA address " + \
|
||||||
|
|
Loading…
Reference in a new issue