2013-10-25 43 views
3

我一直試圖在C++中實現節點服務器來與Python客戶端進行通信。當TFramedTransport打開時,TNonblockingServer在節儉崩潰

這裏是我的代碼:

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

它使用TSimpleServer時完美的作品相同的PB在C++和客戶端上的一個TBufferedTransport

+0

你可以用當前主幹重現這個嗎?如果是,請提交JIRA票。 – JensG

+0

thx爲答案。我只是用libthrift 0.9.1來測試它,而且我遇到了同樣的問題。我在JIRA上創建了一個問題:https://issues.apache.org/jira/browse/THRIFT-2243 –

回答

0

對不起,沒有前面所看到的,但看起來像同一個問題: 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(); 
+0

我試過你的解決方案,仍然有相同的錯誤信息 –

+0

再次審視它後,我認爲你是對的,它確實是TNonblockingServer的一個錯誤。感謝您的耐心;-) – JensG

+0

no pb :)不要猶豫,問我是否有麻煩再現它 –