bad httplib latency due to IPv6 use

Roy Smith roy at panix.com
Wed Oct 17 08:17:46 EDT 2012


In article <1s42l9-9al.ln1 at satorlaser.homedns.org>,
 Ulrich Eckhardt <ulrich.eckhardt at dominolaser.com> wrote:

> Hi!
> 
> I noticed yesterday that a single HTTP request to localhost takes 
> roughly 1s, regardless of the actually served data, which is way too 
> long. After some digging, I found that the problem lies in 
> socket.create_connection(), which first tries the IPv6 ::1 and only then 
> tries the IPv4 127.0.0.1. The first one times out after 1s, causing the 
> long latency.
> 
> What I'm wondering is this:
> 1. The server only serves on IPv4, changing this to IPv6 would probably 
> help. However, I wouldn't consider this a bug, or?

This is most likely a configuration problem on your server.  You don't 
say what kind of system you're using, so I can only guess at the exact 
answer, but here's some suggestions.

Look at your /etc/hosts file.  What entries do you have for localhost?  
For example, on my OSX laptop, I've got:

127.0.0.1   localhost
::1             localhost 
fe80::1%lo0 localhost

which gives three IP addresses (one IPv4, two IPv6) for "localhost".  
This works because the box is properly configured for IPv6 (i.e. all 
services of interest listen on both protocols).  On the other hand, this 
is on a linux box I have:

127.0.0.1   localhost
::1     ip6-localhost ip6-loopback

Now, localhost only gives me the IPv4 address.  If I want to connect to 
localhost with IPv6, I have to explicitly say "ip6-localhost".

My guess is that you have some variation of the first example, and what 
you need is some variation on the second.

In the alternative, you need to fix up your HTTP server to listen on 
both protocols.  For sure, in the long term, that's the right solution, 
because Real Soon Now, we're going to run out of IPv4 addresses and 
everybody is going to switch to IPv6.  Of course, that's been true for 
about the past 15 years, but now it's really, really true.



More information about the Python-list mailing list