You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Stijn Vermeir <st...@dioss.com> on 2016/07/06 10:29:34 UTC

Thrift C++ THttpTransport bug

Hello,

I think I discovered a bug in THttpTransport.cpp that caused a Thrift call
to potentially hang when receiving a certain amount of data in chunked mode.

The problem was that Thrift reads blocks of 512 (default) bytes from the
TCP socket, but the THttpTransport layer didn't check for bytes that were
already in memory when processing chunks inside that last block read from
the TCP socket. It actually tried to read from the socket before checking
the already available data in its memory buffer. It tried to read from a
socket, which had no more data, causing it to block forever. By removing
the refill() call on line 88, the problem was fixed. In the rest of the
THttpTransport code, data is read from the socket when necessary, so
removing this line doesn't seem to break anything.
This is the code that sets up the protocol passed to the constructor of our
generated thrift client:
boost::shared_ptr<TTransport> socketTransport(new TSocket(address, port));
boost::shared_ptr<TTransport> bufferedTransport(new
TBufferedTransport(socketTransport));
boost::shared_ptr<TTransport> httpTransport(new
THttpClient(bufferedTransport, address, thriftRequestPath_));
boost::shared_ptr<TProtocol> jsonProtocol(new TJSONProtocol(httpTransport));

The bug only occurs when the last data on the socket contains 2 or more
chunks: See snippet of end of data that triggered the bug:
...
AAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAQQAAAAAAAAAAAAAAAAAAAAAAAACggAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAACggAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAACggAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAACggAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAACggAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAIgAAAAAAAAAAAAAAARQAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
02
AA
85
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"}}]}}]
0

Marked in yellow are the length of the chunks.


Kind regards,

Stijn Vermeir.