Thrift: Mon Feb 3 14:55:41 2014 TSocket::open() connect() <Host: localhost Port: 9160>Connection refused

As I am working on the system, I often saw this error saying that the server could not connect.

I now know exactly why it happens, and have a very simple solution.

When I setup the Snap! C++ server to connect to the Cassandra server, I used "localhost" as the address. Since we only want to connect to Cassandra locally while doing development (once installed, not so much!)

The result of using localhost is that the address lookup returns two addresses:

IPv6 or [::1]
IPv4 or 127.0.0.1

Then the Thrift library decides to first test the IPv6 address (which makes sens, they are better qualified and therefore more likely to get you where you're traffic is expected to go.) That address fails, and Thrift generates that error saying that the connection was refused, because no one is listening on that port.

Then Thrift tries the IPv4 address and that works. So in other words, everything works as expected only we get an error in between. I think Thrift should be silent unless all addresses fail, but I guess I don't have control over that. And at this time I have not seen a setup for Cassandra to listen on IPv6.

So... the solution is to use 127.0.0.1 as the Cassandra IP address and not localhost. That resolves the problem at once. No more silly warnings from Thrift.

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly