[Python-Dev] socket.create_connection slow
Tres Seaver
tseaver at palladion.com
Wed Jan 14 16:52:29 CET 2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Michael Foord wrote:
> Victor Stinner wrote:
>> Hi,
>>
>> Le Wednesday 14 January 2009 12:23:46 Kristján Valur Jónsson, vous avez
>> écrit :
>>
>>> socket.create_connection() trying to connect to ("localhost", port)
>>> (...)
>>> return an AF_INET6 entry before the AF_INET one and try connection
>>> to that. This connect() attemt fails after approximately one second,
>>> after which we proceed to do an immediately successful connect() call
>>> to the AF_INET address.
>>>
>> This is the normal behaviour of dual stack (IPv4+IPv6): IPv6 is tried before
>> IPv4. SocketServer uses AF_INET by default, so the "IPv6 port" is closed on
>> your host. Why does it take so long to try to connect to the IPv6 port? On
>> Linux, it's immediate:
>> ----
>> $ time nc6 ::1 8080
>> nc6: unable to connect to address ::1, service 8080
>>
>> real 0m0.023s
>> user 0m0.000s
>> sys 0m0.008s
>> ----
>>
>> On my host (Ubuntu Gutsy), "localhost" name has only an IPv4 address. The
>> address "::1" is "ip6-localhost" or "ip6-loopback".
>>
>> You should check why the connect() to IPv6 is so long to raise an error. About
>> the test: since SocketServer address family is constant (IPv4), you can force
>> IPv4 for the client.
>>
>>
> This is something of a bugbear on Vista in general. Doing local
> web-development with localhost can be really painful until you realise
> that switching to 127.0.0.1 solves the problem...
It barfs on Macs as well: indeed, it is worse, because the connection
just fails there, rather than trying IPv6 and then falling back to IPv4.
For instance, tunneling a connection over SSH to a Mac box via '-L
9999:localhost:9999' will fail to connect at all, unless the server is
listening on IPv6.
Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 tseaver at palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFJbgo9+gerLs4ltQ4RAvK9AKCfWhQx7ntw+sUNK7FCPU+Kb9jp5QCdEqCu
9BXvzTgBKipSCtA3SdydqjI=
=tYDj
-----END PGP SIGNATURE-----
More information about the Python-Dev
mailing list