【问题标题】:TNonblockingServer in thrift crashes when TFramedTransport opens当 TFramedTransport 打开时,thrift 中的 TNonblockingServer 崩溃
【发布时间】:2013-11-04 08:45:42
【问题描述】:

我一直在尝试用 C++ 实现一个 thrift 服务器来与 Python 客户端通信。

这是我的代码:

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 客户端代码:

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

当我启动服务器然后启动客户端时,我得到以下信息:

在客户端(Python):

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

在服务器端(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

我正在使用 libthrift 0.8.0,并且与 libthrift 0.9.1 具有相同的 pb

在 C++ 上使用 TSimpleServer 并在客户端使用 TBufferedTransport 时,它可以完美运行

【问题讨论】:

  • 你能用当前的主干重现这个吗?如果是,请提交 JIRA 票证。
  • 感谢您的回答。我刚刚用 libthrift 0.9.1 对其进行了测试,我遇到了同样的问题。我在 JIRA 上创建了一个问题:issues.apache.org/jira/browse/THRIFT-2243

标签: c++ python multithreading thrift


【解决方案1】:

抱歉,之前没见过,但看起来是同样的问题: Service Multiplexing using Apache Thrift

简而言之,您必须使用两侧有框架的,或者不使用。

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

【讨论】:

  • 再看一遍,我觉得你说得对,确实是TNonblockingServer的bug。感谢您的耐心等待 ;-)
  • no pb :) 如果您在复制它时遇到问题,请随时问我
猜你喜欢
  • 1970-01-01
  • 2013-02-23
  • 1970-01-01
  • 1970-01-01
  • 2016-04-07
  • 1970-01-01
  • 2021-08-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多