[Python-Dev] socket.create_connection slow (original) (raw)

Kristján Valur Jónsson kristjan at ccpgames.com
Wed Jan 14 15:35:58 CET 2009


I have no idea why the connect refusal takes so long. Maybe it's a vista thing? from socket import * socket(AF_INET6).connect(("::1", 8080))

takes about one second to report active refusal. But so does an IPv4 connect. Maybe it is some kind of DOS attack throttling? I couldn't find any info.

I've already asked the client in the test to use IPV4 by specifying the connection address as an IPv4 tuple ("http://127.0.0.1:..."). I see no other way to do it without extensive subclassing because the HTTPConnection() class uses socket.create_connection().

Cheers,

Kristján

-----Original Message----- From: python-dev-bounces+kristjan=ccpgames.com at python.org [mailto:python-dev-bounces+kristjan=ccpgames.com at python.org] On Behalf Of Victor Stinner Sent: 14. janúar 2009 12:46 To: python-dev at python.org Subject: Re: [Python-Dev] socket.create_connection slow

Hi,

Le Wednesday 14 January 2009 12:23:46 Kristján Valur Jónsson, vous avez écrit :

socket.createconnection() trying to connect to ("localhost", port) (...) return an AFINET6 entry before the AFINET 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 AFINET 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.

-- Victor Stinner aka haypo http://www.haypocalc.com/blog/


Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/kristjan%40ccpgames.com



More information about the Python-Dev mailing list