0
votes

I am running the Facebook Thrift service on my machine. I used a sample code to show its working:

import asyncio

from fbnet.command_runner.thrift_client import AsyncioThriftClient

# Import FCR Thrift Types
from fbnet.command_runner_asyncio.CommandRunner import ttypes as fcr_ttypes

# Import FCR Service Client
from fbnet.command_runner_asyncio.CommandRunner.Command import Client as FcrClient

import getpass

# Device Information
hostname = 'my_vm'
username = 'root'
password = getpass.getpass('%s Password: ' % username)

# Destination device
device = fcr_ttypes.Device(hostname=hostname, username=username,     password=password)

async def run(cmd, device):
    async with AsyncioThriftClient(FcrClient, 'x.x.x.x',22 ) as client:
        res = await client.run(cmd, device)
        # type of res is `struct CommandResult`
        print(res.output)

loop = asyncio.get_event_loop()
loop.run_until_complete(run('uname -a', device))

However I am getting the following error:

Frame size 1397966893 too large for THeaderProtocol Traceback (most recent call last):
File "pgm1.py", line 28, in loop.run_until_complete(run('uname -a', device))
File "/usr/local/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete return future.result()
File "pgm1.py", line 23, in run res = await client.run(cmd, device) thrift.transport.TTransport.TTransportException: Connection closed

Any ideas on how to correct this?

1
Where does that strange value of 1397966893 = 0x5353482D come from? Some uninitialized variable?JensG
I don't know anything about thrift, but 0x5353482D is the four characters "SSH-", which happens to be the first data sent by an ssh server when something connects to it. My guess is that you're trying to start up thrift on a raw TCP socket connected to the ssh server.Kenster

1 Answers

0
votes

@Kenster's comment indicates the real problem here.

0x5353482D is the four characters "SSH-", which happens to be the first data sent by an ssh server when something connects to it

There are some server implementations that require TFramedProtocol by design. In other words, it is mandatory, the client has to use it, simply because the server expects it that way.

The insight comes quickly to one who knows that TFramedProtocol adds a 4 byte header carrying the frame size of the data to follow. If the client does not use TFramedProtocol, the server will interpret the first four databytes as the frame size - hence the error message.

Solution

Add TFramedProtocol on the client side to the Thrift transport/protocol stack.