saghul/aiodns

gethostbyname defaults to ipv6

gwillem opened this issue · 5 comments

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()

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

Closing since it needs to be solved upstream.

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

Possibly, PRs are welcome :-)