python / asyncio

asyncio historical repository
https://docs.python.org/3/library/asyncio.html
1.04k stars 177 forks source link

Implement "Happy Eyeballs" (RFC 6555) for dual-stack create_connection() #86

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
See http://tools.ietf.org/html/rfc6555

See also the HostnameEndpoint class in Twisted (new in Twisted 13.2).

Original issue reported on code.google.com by gu...@dropbox.com on 12 Nov 2013 at 10:10

GoogleCodeExporter commented 9 years ago
Note that the RFC requires caching the info about whether IPv6 works or not for 
a particular destination address (host+port). The cache should time out after 
10 minutes. It also requires preferring IPv6 (if it is the first address 
returned by getaddrinfo()). It also specifies using a delay of 150-250 msec in 
case no cache is used.

Original comment by gvanrossum@gmail.com on 15 Nov 2013 at 9:42

pavlix commented 8 years ago

Does create_connection() support servname for getaddrinfo() by the way?

gvanrossum commented 8 years ago

@pavlix: Can you clarify the question?

ajdavis commented 8 years ago

If I understand correctly, the answer's "yes", asyncio supports the same args to create_connection as the standard socket.getaddrinfo call does. The "port" argument maps to the POSIX getaddrinfo argument "servname", which can be an actual port or a service name like "http":

>>> import asyncio
>>> class MyProto(asyncio.Protocol):
...     pass
...     
>>> loop = asyncio.get_event_loop()
>>> future = loop.create_connection(MyProto, 'python.org', 'http')
>>> loop.run_until_complete(future)
(<_SelectorSocketTransport fd=7 read=polling write=<idle, bufsize=0>>, <MyProto object at 0x1046687f0>)
pavlix commented 8 years ago

Exactly as @adjavis wrote. I'm writing tests for various IPv4/IPv6 configuration with careful syscall checks and I have just added support for python using getaddrinfo() and sockets (link). Looks like it's also time to add a asyncio based test

pavlix commented 8 years ago

So I know have the test using asyncio and can easily confirm that fallback to IPv4 is delayed by an actual IPv6 TCP timeout. Let me know if I can help testing the feature.

gvanrossum commented 8 years ago

But who's going to write the patch?

pavlix commented 8 years ago

I don't want to make false promises and the test linked above was my first asyncio code ever. But I would consider it unless someone does it first.

pavlix commented 8 years ago

Also, I will definitely be implementing the happy eyeballs RFC in C in the netresolve project which already supports a non-standard variant of happy eyeballs.