thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Partridge, Lucas (GE Aviation)" <Lucas.Partri...@ge.com>
Subject RE: Python clients can't connect to Thrift services running on "localhost" when no network connection is available
Date Wed, 30 Apr 2014 08:35:23 GMT
Thanks Lars.  So it sounds like this might be an issue with Python itself rather than the way
the Python code for Thrift in TSocket.open() interprets "localhost".

-----Original Message-----
From: Lars Benner [mailto:LBenner@tomtec.de] 
Sent: 29 April 2014 11:28
To: user@thrift.apache.org
Subject: RE: Python clients can't connect to Thrift services running on "localhost" when no
network connection is available

Hi Lucas,

I came across a similar issue in a completely different area (TCP/IP connection between Qt
and Ruby). 

Depending on the language and the available IP stacks, localhost can be resolved to an IPv4
(normally 127.0.0.1) or IPv6 (normally ::1) address. Connecting from one to other does not
work.

I also know no better solution than using '127.0.0.1' for ensuring an IPv4 connection.
 
Best Regards,
- Lars

-----Original Message-----
From: Partridge, Lucas (GE Aviation) [mailto:Lucas.Partridge@ge.com] 
Sent: Tuesday, April 29, 2014 11:24 AM
To: user@thrift.apache.org
Subject: Python clients can't connect to Thrift services running on "localhost" when no network
connection is available

I'm not sure whether this is a bug or something different between Java and Python but I thought
other people might like to know this...

I had a Thrift 0.9.0 service running on my local machine in C#.  Java clients to this service
could connect using "localhost" even when no network connection was available but Python clients
failed with:

  File "C:\Python27\lib\site-packages\thrift-0.9.0-py2.7.egg\thrift\transport\TSocket.py",
line 99, in open
    message=message)
thrift.transport.TTransport.TTransportException: Could not connect to localhost:9092

The workaround is to use "127.0.0.1" in Python clients. This is not necessary for Java clients.
Python test script:

from thrift.transport import TSocket

#host = "127.0.0.1" # Works
host = "localhost" # Fails when no network connection is available port = 9092

transp = TSocket.TSocket(host, port)
transp.open()
print 'Transport opened'
transp.close()
print 'Transport closed'

The Java equivalent runs fine, however:

TTransport transport = new TSocket("localhost", 9092); try {
                transport.open(); // Works even if no network connection is available.
...

Thanks,
Lucas.

Mime
View raw message