473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Very slow opening of client connections to localhost with httplib

I am using xmlrpclib (based on httplib) in Python 2.3 on Mandrake
Linux.

When my client attempts to connect to a server using a
"http://localhost:port" style URL there is a long delay before the
connection is established (it finally works).

This certainly smells a name resolution problem but ping localhost,
telnet localhost etc all work fine.

Tracking down a bit it appears that the problem comes from the
getaddrinfo() call in code in HttpConnection.connect() :
def connect(self):
"""Connect to the host and port specified in __init__."""
msg = "getaddrinfo returns an empty list"
for res in socket.getaddrinfo(self.host, self.port, 0,
socket.SOCK_STREAM):

To test this I did :

import socket
socket.getaddrinfo("localhost", 10000, 0, socket.SOCK_STREAM)

and sure enough it blocked for several seconds before finally
returning 127.0.0.1

However
socket.gethostbyname("localhost")
returns immediately

If I remplace the 0 in the getaddrinfo call above by socket.AF_INET
all is fine as well.

So I did a tcpdump to see what it was sending to the nameserver and
got

18:36:01.790045 X.Y.Z.41.32961 > X.Y.Z.12.53: 42057+ AAAA?
localhost.besancon.parkeon.com. (48) (DF)
18:36:01.790526 X.Y.Z.12.53 > X.Y.Z.41.32961: 42057* 0/1/0 (95)
18:36:01.790652 X.Y.Z.41.32961 > X.Y.Z.12.53: 42058+ AAAA? localhost.
(27) (DF)
18:36:06.792898 X.Y.Z.41.32962 > X.Y.Z.215.53: 42058+ AAAA?
localhost. (27) (DF)
18:36:06.793134 X.Y.Z.215.53 > X.Y.Z.41.32962: 42058 ServFail 0/0/0
(27)
18:36:06.793301 X.Y.Z.41.32962 > X.Y.Z.12.53: 42058+ AAAA? localhost.
(27) (DF)
18:36:11.802998 X.Y.Z.41.32963 > X.Y.Z.215.53: 42058+ AAAA?
localhost. (27) (DF)
18:36:11.803222 X.Y.Z.215.53 > X.Y.Z.41.32963: 42058 ServFail 0/0/0
(27)
18:36:13.356344 X.Y.Z.12.53 > X.Y.Z.41.32959: 42056 ServFail 0/0/0
(27)

(my machine is X.Y.Z.41 and the NS is X.Y.Z.12)

When AF_INET or gethostbyname() is used there is no network
communication.

This appears to be a problem with IPV6 DNS queries?? (the AAAA
records). We don't use IPV6 but the 0 parameter (AF_UNSPEC) used in
httplib seems to cause them to be sent.

Anyone else had this problem or got any ideas?

The problem does NOT occur under windows.

Thanks,

Martin
Jul 18 '05 #1
2 5189
Martin Fuzzey wrote:

To test this I did :

import socket
socket.getaddrinfo("localhost", 10000, 0, socket.SOCK_STREAM)

and sure enough it blocked for several seconds before finally
returning 127.0.0.1

However
socket.gethostbyname("localhost")
returns immediately


Any chance your /etc/host.conf, /etc/resolv.conf or /etc/hosts files
are buggering this up somehow? (It doesn't explain gethostbyname()
returning immediately, unless perhaps that function internally handles
localhost "magically".) Just a thought.

In my experience, delays like this generally result from host.conf
having "order bind,hosts" instead of the other way around, plus perhaps
an inappropriate "options timeout:xxx" value in resolv.conf.

I haven't ever seen an issue with localhost, however, but I've never
been on a machine that didn't have the right entry in /etc/hosts.

-Peter
Jul 18 '05 #2
In article <8c**************************@posting.google.com >, Martin Fuzzey wrote:
I am using xmlrpclib (based on httplib) in Python 2.3 on Mandrake
Linux.

When my client attempts to connect to a server using a
"http://localhost:port" style URL there is a long delay before the
connection is established (it finally works). .... import socket
socket.getaddrinfo("localhost", 10000, 0, socket.SOCK_STREAM)

and sure enough it blocked for several seconds before finally
returning 127.0.0.1

If I remplace the 0 in the getaddrinfo call above by socket.AF_INET
all is fine as well.


Try adding
::1 localhost

to your /etc/hosts

Or delete IPv6 from your kernel.

--
Jarkko Torppa, Elisa Internet
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Roger Binns | last post by:
I have just spent several weeks mashing xmlrpc, httplib and SSL (from M2Crypto) to work together. The current standard library has several problems: - Builtin SSL is pretty much useless if you...
2
by: Adam Ryan | last post by:
Hi, I am seeing very slow connections from some client enterprise managers to server. Even at server level it takes 1 minute or less to open a database. I have adjusted some of the memory...
5
by: Carlos Moreno | last post by:
Hi, I'm experiencing some really odd behaviour after upgrading to postgresql 7.4.1 We have three different machines: 1) Dual Athlon, 1GB RAM running RedHat 7.3 with all the updates...
6
by: B B | last post by:
Okay, here is what's happening: I have a reasonably fast laptop (1.4 GHz Mobile M, so comparable to 2.5GHz P4) doing .net development. Running Windows XP pro, SP2 IIS is installed and running...
50
by: diffuser78 | last post by:
I have just started to learn python. Some said that its slow. Can somebody pin point the issue. Thans
5
by: runningwild | last post by:
Helo, This is the first time I have cared about httplib's HTTPSConnection. In the docs I read "Note: HTTPS support is only available if the socket module was compiled with SSL support." ...
0
by: mlfblom | last post by:
Hi, I am running visual studio 2005 on a Vista Ultimate client. I have created a remote site on a Windows 2003 R2 server. This site has about 100 aspx, many App_Code files and several references...
1
by: welcomestocontact | last post by:
Hi, I am writing http protocol to get some data from servers. If i was using my localhost, getting replay from local and if want access other remote sites, i am getting error. Please reply it ...
0
by: reacocard | last post by:
Hi, I'm writing a download manager in python, and httplib is being very slow when pulling from localhost or even other servers on the local network. I'm getting about 10MB in 14s with httplib,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.