[Python-Dev] socket.create_connection slow

Kristján Valur Jónsson kristjan at ccpgames.com
Wed Jan 14 12:23:46 CET 2009


Greetings.
I spent the morning trying to find out why the disabled tests in test_xmlrpc.py ran so slowly on my vista box.
After much digging, I found that it boiled down to socket.create_connection() trying to connect to "localhost", port.

You see, it does a getaddrinfo() and then tries to connect using all the various addresses it finds until it succeeds.
On Vista, it will 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.

Now, I did fix this in test_xmlrpc.py by just speficying the loopback address, but I wonder if this might not be a problem in general?

I can think of two things to make this better:

1)      Make sure that AF_INET addresses are tried first in socket.create_connection()

2)      Have the SocketServer create a listening socket for each address family by default.

Any thoughts?

K
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20090114/be115ba0/attachment.htm>


More information about the Python-Dev mailing list