Using HBase/Thrift through the Rackspace Load Balancer

Using the binary Thrift protocol through a load balancer can be a little tricky. While it works out of the box in HAProxy, you may run into some slight trouble running it through other load balancers. By default, when trying to access Thrift through the Rackspace Cloud Load Balancers, you may get the following exception:

Traceback (most recent call last):

File "/usr/local/lib/python2.6/dist-packages/Django-1.2-py2.6.egg/django/core/handlers/",
line 100, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.6/dist-packages/Thrift-0.2.0-py2.6-linux-x86_64.egg/thrift/protocol/",
line 126, in readMessageBegin
sz = self.readI32()

File "/usr/local/lib/python2.6/dist-packages/Thrift-0.2.0-py2.6-linux-x86_64.egg/thrift/protocol/",
line 203, in readI32
buff = self.trans.readAll(4)

File "/usr/local/lib/python2.6/dist-packages/Thrift-0.2.0-py2.6-linux-x86_64.egg/thrift/transport/",
line 58, in readAll
chunk =

File "/usr/local/lib/python2.6/dist-packages/Thrift-0.2.0-py2.6-linux-x86_64.egg/thrift/transport/",
line 155, in read
self.__rbuf = StringIO(, self.DEFAULT_BUFFER)))

File "/usr/local/lib/python2.6/dist-packages/Thrift-0.2.0-py2.6-linux-x86_64.egg/thrift/transport/",
line 94, in read
raise TTransportException(type=TTransportException.END_OF_FILE,
message='TSocket read 0 bytes')

thrift.transport.TTransport.TTransportException: TSocket read 0 bytes

After playing around with the HappyBase connection transport settings, I was able to rule out framed versus binary transport as the issue. I was also able to verify that a connection directly to the machine worked.

The issue turned out to be a setting on the Rackspace load balancer.

Rackspace Load Balancer TCP Client First

The default TCP protocol, called simply "TCP", did not work. By changing the setting to "TCP (Client First)", HappyBase was able to connect via Thrift.

What does this setting do? The Rackspace documentation simply says "This protocol is similiar to TCP, but is more efficient when a client is expected to write the data first". This would seem to hint that the regular TCP option attemps to read from the server socket when a client connects, where-as as an RPC protocol, Thrift expects the client to send the first data packet.

I'm currently working at NerdWallet, a startup in San Francisco trying to bring clarity to all of life's financial decisions. We're hiring like crazy. Hit me up on Twitter, I would love to talk.

Follow @chase_seibert on Twitter