chenshuo / muduo

Event-driven network library for multi-threaded Linux server in C++11
https://github.com/chenshuo/muduo
Other
14.64k stars 5.14k forks source link

muduo样例 chatserver:读取客户端数据 报段错误 #641

Closed happyTTQuan closed 2 years ago

happyTTQuan commented 2 years ago

环境: centos7.2 g++ gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC) muduo 2.0.2 boost :boost-1.53.0-28.el7.x86_64 cmake version 3.19.0 安装成功后,用muduo提供的example ,server和client可以正常启动,链接也正常;但是客户端发送数据时,服务端就会崩溃。 具体使用的样例文件为 examples/asio/chat/server_threaded_highperformance.cc examples/asio/chat/client.cc

堆栈信息如下: std::invoke_impl<void, void (LengthHeaderCodec::&)(std::shared_ptr const&, muduo::net::Buffer, muduo::Timestamp), LengthHeaderCodec&, std::shared_ptr const&, muduo::net::Buffer, muduo::Timestamp>(std::invoke_memfun_deref, void (LengthHeaderCodec::&)(std::shared_ptr const&, muduo::net::Buffer, muduo::Timestamp), LengthHeaderCodec&, std::shared_ptr const&, muduo::net::Buffer&&, muduo::Timestamp&&) invoke.h:73 std::invoke<void (LengthHeaderCodec::&)(std::shared_ptr const&, muduo::net::Buffer, muduo::Timestamp), LengthHeaderCodec&, std::shared_ptr const&, muduo::net::Buffer, muduo::Timestamp>(void (LengthHeaderCodec::&)(std::shared_ptr const&, muduo::net::Buffer, muduo::Timestamp), LengthHeaderCodec&, std::shared_ptr const&, muduo::net::Buffer&&, muduo::Timestamp&&) invoke.h:95 std::_Bind<void (LengthHeaderCodec::(LengthHeaderCodec, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::shared_ptr const&, muduo::net::Buffer*, muduo::Timestamp)>::call<void, std::shared_ptr const&, muduo::net::Buffer&&, muduo::Timestamp&&, 0ul, 1ul, 2ul, 3ul>(std::tuple<std::shared_ptr const&, muduo::net::Buffer&&, muduo::Timestamp&&>&&, std::_Index_tuple<0ul, 1ul, 2ul, 3ul>) functional:400 std::_Bind<void (LengthHeaderCodec::(LengthHeaderCodec, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::shared_ptr const&, muduo::net::Buffer, muduo::Timestamp)>::operator()<std::shared_ptr const&, muduo::net::Buffer, muduo::Timestamp, void>(std::shared_ptr const&, muduo::net::Buffer&&, muduo::Timestamp&&) functional:484 std::_Function_handler<void (std::shared_ptr const&, muduo::net::Buffer, muduo::Timestamp), std::_Bind<void (LengthHeaderCodec::(LengthHeaderCodec, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::shared_ptr const&, muduo::net::Buffer, muduo::Timestamp)> >::_M_invoke(std::_Any_data const&, std::shared_ptr const&, muduo::net::Buffer&&, muduo::Timestamp&&) std_function.h:297 operator() functional:2471 muduo::net::TcpConnection::handleRead 0x0000000000418fb5 operator() functional:2471 muduo::net::Channel::handleEventWithGuard 0x0000000000420740 muduo::net::Channel::handleEvent 0x0000000000420ad0 muduo::net::EventLoop::loop 0x0000000000413614 main server_threaded_highperformance.cc:105 __libc_start_main 0x00007ffff7000b35 _start 0x0000000000403b75

happyTTQuan commented 2 years ago

服务端日志: /tmp/tmp.dHyOhmEIHh/cmake-build-debug-local129/tcp_server 12345 20220820 19:21:21.909936 82459 INFO pid = 82459 - server_threaded_highperformance.cc:95 20220820 19:21:27.356151 82459 INFO TcpServer::newConnection [ChatServer] - new connection [ChatServer-0.0.0.0:12345#1] from 127.0.0.1:43330 - TcpServer.cc:80 20220820 19:21:27.356183 82459 INFO 127.0.0.1:43330 -> 127.0.0.1:12345 is UP - server_threaded_highperformance.cc:39

Process finished with exit code 139 客户端日志: /tmp/tmp.AUh1PbFsCX/cmake-build-release-local129/muduo_tcp_client 127.0.0.1 12345 20220820 19:21:27.354819 82511 INFO pid = 82511 - client.cc:72 20220820 19:21:27.355574 82511 INFO TcpClient::TcpClient[ChatClient] - connector 0x12AB240 - TcpClient.cc:69 20220820 19:21:27.355598 82511 INFO TcpClient::connect[ChatClient] - connecting to 127.0.0.1:12345 - TcpClient.cc:107 20220820 19:21:27.356100 82524 INFO 127.0.0.1:43330 -> 127.0.0.1:12345 is UP - client.cc:45 hello world muduo hello world muduo 20220820 19:21:40.625860 82524 INFO 127.0.0.1:43330 -> 127.0.0.1:12345 is DOWN - client.cc:45 20220820 19:21:40.625876 82524 INFO TcpClient::connect[ChatClient] - Reconnecting to 127.0.0.1:12345 - TcpClient.cc:176 20220820 19:21:40.625982 82524 WARN fd = 7 Channel::handle_event() POLLHUP - Channel.cc:91 20220820 19:21:40.625986 82524 ERROR Connector::handleError state=1 - Connector.cc:199 20220820 19:21:40.625993 82524 INFO Connector::retry - Retry connecting to 127.0.0.1:12345 in 500 milliseconds. - Connector.cc:215 20220820 19:21:41.130436 82524 WARN fd = 6 Channel::handle_event() POLLHUP - Channel.cc:91 20220820 19:21:41.130557 82524 ERROR Connector::handleError state=1 - Connector.cc:199 20220820 19:21:41.130626 82524 INFO Connector::retry - Retry connecting to 127.0.0.1:12345 in 1000 milliseconds. - Connector.cc:215 20220820 19:21:42.131305 82524 WARN fd = 6 Channel::handle_event() POLLHUP - Channel.cc:91 20220820 19:21:42.131350 82524 ERROR Connector::handleError state=1 - Connector.cc:199 20220820 19:21:42.131399 82524 INFO Connector::retry - Retry connecting to 127.0.0.1:12345 in 2000 milliseconds. - Connector.cc:215 20220820 19:21:44.133216 82524 WARN fd = 6 Channel::handle_event() POLLHUP - Channel.cc:91 20220820 19:21:44.133260 82524 ERROR Connector::handleError state=1 - Connector.cc:199 20220820 19:21:44.133306 82524 INFO Connector::retry - Retry connecting to 127.0.0.1:12345 in 4000 milliseconds. - Connector.cc:215 ^C Process finished with exit code 130

happyTTQuan commented 2 years ago

c++11 Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

happyTTQuan commented 2 years ago

在clion中cmake远程编译会有这个问题,手工在linux上编译是可以正常运行的