aio-libs / aiodns

Simple DNS resolver for asyncio
https://pypi.python.org/pypi/aiodns
MIT License
538 stars 69 forks source link

gethostbyname defaults to ipv6 #23

Closed gwillem closed 7 years ago

gwillem commented 8 years ago

Not sure if it's a bug or intended behaviour, but it's bitten me and other users (probably #22) of aiohttp since they switched to family=0 per default. Most Linux distro's ship with IPv6 enabled (luckily) but most don't have a IPv6 route set up yet.

Output:

Async: ['2a03:b0c0:2:d0::27d:6001']
Socket: ['188.166.29.234', '2a03:b0c0:2:d0::27d:6001']

Test:

import asyncio
import aiodns
import socket

HOST = 'www.vinyl-lp.com'
FAMILY = 0 
PORT = 80

async def aiodns_gethostbyname():
    resolver = aiodns.DNSResolver()
    resp = await resolver.gethostbyname(HOST, FAMILY)
    print("Async: {}".format(resp.addresses))

def regular_gethostbyname():
    resp = socket.getaddrinfo(HOST, PORT, family=FAMILY, proto=socket.IPPROTO_TCP)
    ips = [x[4][0] for x in resp]
    print("Socket: {}".format(ips))

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(aiodns_gethostbyname())
    loop.close()

    regular_gethostbyname()
saghul commented 8 years ago

aiodns uses pycares which in turn uses c-ares. Can you check at what level the default is applied?

dimbleby commented 7 years ago

Per c-ares/c-ares#70

saghul commented 7 years ago

Closing since it needs to be solved upstream.

skrech commented 2 years ago

Hello, I see that in c-ares has closed the issue with introduction of ares_getaddrinfo. Is it possible for aiodns to utilize it?

saghul commented 2 years ago

Possibly, PRs are welcome :-)