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

TcpClient客户端tcpconnection.forceClose(),onconnect回调函数收到断联的消息后coredump #651

Open yuzhenboy opened 1 year ago

yuzhenboy commented 1 year ago

ubuntu 16.04 使用的是muduo c++11版

目的在没有接收到信息超过2分钟后,会调用forceClose强制断开连接,然后收到注册的连接回调函数的断联消息后,就会崩溃,初步分析只有在发命令的时候偶尔会发生这种情况,在没有发命令的时候,没有出现过,现在我的处理是:在准备关闭连接之前提早将连接标志位置false,使得不会在发送命令,过几秒后,再调用forceClose函数。

崩溃函数: void EPollPoller::updateChannel(Channel* channel) { Poller::assertInLoopThread(); const int index = channel->index(); if (index == kNew || index == kDeleted) { // a new one, add with EPOLL_CTLADD int fd = channel->fd(); if (index == kNew) { assert(channels.find(fd) == channels.end()); channels[fd] = channel; } else // index == kDeleted { assert(channels.find(fd) != channels.end()); assert(channels_[fd] == channel); }

channel->set_index(kAdded);
update(EPOLL_CTL_ADD, channel);

} else { // update existing one with EPOLL_CTLMOD/DEL int fd = channel->fd(); (void)fd; assert(channels.find(fd) != channels.end()); assert(channels[fd] == channel); assert(index == kAdded); if (channel->isNoneEvent()) { update(EPOLL_CTL_DEL, channel); channel->set_index(kDeleted); } else { update(EPOLL_CTL_MOD, channel); } } }

coredump信息堆栈如下: Aborted at 1657443526 (unix time) try "date -d @1657443526" if you are using GNU date PC: @ 0x0 (unknown) SIGABRT (@0x7a2) received by PID 1954 (TID 0x7f422cff9700) from PID 1954; stack trace: @ 0x7f423aaee980 (unknown) @ 0x7f4239deafb7 gsignal @ 0x7f4239dec921 abort @ 0x7f4239ddc48a (unknown) @ 0x7f4239ddc502 __assert_fail @ 0x7f423e24640c yuto::net::EPollPoller::updateChannel() @ 0x7f423e24c014 yuto::net::Connector::connecting() @ 0x7f423e24fea9 yuto::net::TcpClient::removeConnection() @ 0x7f423e249672 yuto::net::TcpConnection::handleClose() @ 0x7f423e2420b9 yuto::net::EventLoop::doPendingFunctors() @ 0x7f423e242249 yuto::net::EventLoop::loop() @ 0x7f423a810a50 (unknown) @ 0x7f423aae36db start_thread @ 0x7f4239ecd71f clone @ 0x0 (unknown)

chenshuo commented 1 year ago

Please provide a SSCCE: Short, Self Contained, Correct (Compilable), Example.

yuzhenboy commented 1 year ago

Please provide a SSCCE: Short, Self Contained, Correct (Compilable), Example.

不一定出现,我自己测试的时候多线程一边forceClose 一边发送消息 也没出现…………

chenshuo commented 1 year ago

不一定出现不要紧。至少要有一个完整的能运行的程序,不然光凭文字描述我很难复现你遇到的场景。

另外,我不认识 yuto::net 这个 namespace,如果你用的不是 muduo 库本尊,请考虑把 issue 提到 yuto 库那里。