Reputation: 181
I'm experimenting with a very simple Apache Thrift server and client written in C++ using Visual Studio 2015. The code is based on the the official Apache Thrift samples.
I'm using the latest version of Thrift (0.10.0), Boost (1.64.0) and OpenSSL (1.1.0e).
Each call from the client to the server triggers a TTransportException in TTransport.h line 43:
throw TTransportException(TTransportException::END_OF_FILE, "No more data to read.");
Here's my test.thrift file:
namespace cpp test
service Test {
void ping()
}
The thrift compiler generates Test.h which is #included below in both server and client (not showing the actual code as it's autogenerated).
thrift header files included in both client and server:
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TTransportUtils.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TBufferTransports.h>
#include <Test.h>
client main:
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
using namespace std;
int main()
{
boost::shared_ptr<TTransport> socket(new TSocket("localhost", 9090));
boost::shared_ptr<TTransport> transport(new TFramedTransport(socket));
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
test::TestClient client(protocol);
try {
transport->open();
client.ping();
cout << "ping()" << endl;
transport->close();
}
catch (TException& tx) {
cout << "ERROR: " << tx.what() << endl;
}
return 0;
}
and server main:
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
using namespace std;
class TestHandler : virtual public test::TestIf {
public:
TestHandler() {
// Your initialization goes here
}
void ping() {
// Your implementation goes here
printf("ping\n");
}
};
int main()
{
std::cout << "Starting thrift server thread" << std::endl;
int port = 9090;
boost::shared_ptr<TestHandler> handler(new TestHandler());
boost::shared_ptr<TProcessor> processor(new test::TestProcessor(handler));
boost::shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
boost::shared_ptr<TTransportFactory> transportFactory(new TFramedTransportFactory());
boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
boost::shared_ptr< apache::thrift::server::TSimpleServer > server = boost::shared_ptr< TSimpleServer>(new TSimpleServer(processor, serverTransport, transportFactory, protocolFactory));
server->serve();
return 0;
}
I also tried using TBufferedTransport and TJSONProtocol with the same result.
The fact that an exception is thrown indicates that this is not normal functioning, however, the call is received and processed (the exception happens after the call to TestHandler::ping()) and the server continues to listen to and receive requests (triggering the same error each time), so it is a recoverable condition.
So I'm wondering why this is happening, is it something that can/should be fixed, and how, and if not, is it safe to use the server despite this exception.
Upvotes: 2
Views: 1728
Reputation: 13411
By design.
Thrift libraries are implemented in the way, where the end of an connection is signaled internally by throwing an TTransportException
.
Upvotes: 2