简体   繁体   English

当TFramedTransport打开时,节俭中的TNonblockingServer崩溃

[英]TNonblockingServer in thrift crashes when TFramedTransport opens

I've been trying to implement a thrift server in C++ to communicate with a Python client. 我一直在尝试用C ++实现一个thrift服务器来与Python客户端通信。

here is my code: 这是我的代码:

C++ server: C ++服务器:

shared_ptr<ThriftHandler> _handler (new myHandler());
shared_ptr<TProcessor> _processor (new myService(_handler));
shared_ptr<TProtocolFactory> _protocolFactory (new TBinaryProtocolFactory());
shared_ptr<ThreadManager> _threadManager = ThreadManager::newSimpleThreadManager(15);
shared_ptr<PosixThreadFactory> _threadFactory(new PosixThreadFactory());
_threadManager->threadFactory(_threadFactory);
_threadManager->start();

shared_ptr<TNonblockingServer> _server(new TNonblockingServer(_processor, _protocolFactory, 9090 ,_threadManager));;
_server->serve();

Python Client code: Python客户端代码:

transport = TSocket.TSocket(host, port)
transport = TTransport.TFramedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = MyService.Client(protocol)
transport.open()
log.info("connection success!")

When I start the server and then the client, I get the following: 当我启动服务器然后启动客户端时,我得到以下内容:

On the client side (Python): 在客户端(Python):

./myPythonExec.py
connection success!
socket.error: [Errno 104] Connection reset by peer

On the server side (c++): 在服务器端(c ++):

assertion " 0 " failed
0  0x00007ffff0942425 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
1  0x00007ffff0945b8b in __GI_abort () at abort.c:91
2  0x00007ffff093b0ee in __assert_fail_base (fmt=<optimized out>, assertion=0x7ffff1438f1a "0", 
file=0x7ffff1439298 "src/server/TNonblockingServer.cpp", line=<optimized out>, function=<optimized out>) at assert.c:94
3  0x00007ffff093b192 in __GI___assert_fail (assertion=0x7ffff1438f1a "0", file=0x7ffff1439298 "src/server/TNonblockingServer.cpp", 
line=558, function=0x7ffff1439c60 "void apache::thrift::server::TNonblockingServer::TConnection::workSocket()") at assert.c:103
4  0x00007ffff14336e4 in apache::thrift::server::TNonblockingServer::TConnection::workSocket (this=0x7fffc0004ac0)
at src/server/TNonblockingServer.cpp:558
5  0x00007ffff11ed94c in event_base_loop () from /usr/lib/libevent-2.0.so.5

I'm using libthrift 0.8.0 and have the same pb with libthrift 0.9.1 我正在使用libthrift 0.8.0并且与libthrift 0.9.1具有相同的pb

It works perfectly when using a TSimpleServer on C++ and a TBufferedTransport on the client side 在C ++上使用TSimpleServer和在客户端使用TBufferedTransport时,它非常有效

Sorry, have not seen earlier, but looks like the same issue: Service Multiplexing using Apache Thrift 对不起,以前没有见过,但看起来像是同一个问题: 使用Apache Thrift进行服务多路复用

In short, you have to use either framed on both sides, or none. 简而言之,您必须使用双面框架或无框架。

shared_ptr<TTransportFactory> _transportFactory(new TFramedTransportFactory());
shared_ptr<TNonblockingServer> _server(
   new TNonblockingServer(
     _processor, 
     _transportFactory,
     _transportFactory,
     _protocolFactory, 
     _protocolFactory, 
     9090,
     _threadManager));
_server->serve();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM