Thrift第七课 服务器多线程发送异常

场景

C++服务器端为每一个客户端建立多线程发送,没有添加锁,会触发异常:received invalid message type 3 from client。导致服务器端主动断开跟客户端的连接

打印出错的代码在TDispatchProcessor.h文件

相关堆栈代码:

  apache::thrift::TOutput::errorTimeWrapper(const char * msg) 行 134 C++

  apache::thrift::TOutput::printf(const char * message, ...) 行 42 C++

apache::thrift::TDispatchProcessor::process(boost::shared_ptr<apache::thrift::protocol::TProtocol> in,boost::shared_ptr<apache::thrift::protocol::TProtocol> out, void * connectionContext) 行 116 C++


结论

调用发送的接口最好加锁,或者是单线程发送


猜你喜欢

转载自blog.51cto.com/fengyuzaitu/2110789