-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在TcpClient析构时coredump #488
Comments
请提供完整能复现 coredump 的代码。 另外,你可以在 Channel 的析构函数里打印一下 this 指针,然后在 handleEvent 里同样打印 this 指针,看看 Channel 是不是在 handleEvent() 之前被析构了。 |
关于这个问题,我其实有一些想法,这个库,或者很多库,使用回调时,大多会遇到一个问题,就是绑定的对象的生命周期的问题, |
而大多数有事件循环的框架,不存在这种问题,是在于他们提供了对对象生命的监控,比如通过继承Object来使框架保持对自己的监控,通过Event驱动对象,如果Event指向的对象已经被销毁了,就不会分发这个事件了。总体来说,这种问题也算是一种bug吧 |
在删除TcpClient同样也会遇到类似的问题:
|
针对这个问题,我在 cpp-tbox 中使用了比较另类的方法。
如果是智能指针的话,就:
在我的开源项目 cpp-tbox 中,有大量的使用。
|
另外,我在大部分的事件对象中都有加 cb_level_,用于监控是否存在在自己的回调中析构自己的情况。
在析构的时候,就检查cb_level_是否为0。如果为0,则表示发生了这情况。就报断言。 |
Linux distro and version? x86 or ARM? 32-bit or 64-bit?
x86 64-bit
Branch (cpp98/cpp11/cpp17) and version of muduo?
v1.1.0
我们在使用muduo时出现coredump的情况,排查以后发现是出现在TcpClient.cc的91行,如下图:
![image](https://user-images.githubusercontent.com/4918159/95840548-da9daa80-0d76-11eb-8f22-326ace0be20a.png)
这里有一个FIXME没有看明白是什么意思,所以想了解一下这个FIXME具体意义以及是否能修复
最终的问题出现在Channel.cc的71行,如下图:
![image](https://user-images.githubusercontent.com/4918159/95840930-5c8dd380-0d77-11eb-9a29-63b38f2b183f.png)
在tie_.lock()时出现coredump,应该是tie_成员变量已经不能正常访问了
具体堆栈信息如下:
![image](https://user-images.githubusercontent.com/4918159/95841351-d625c180-0d77-11eb-8711-8d3aa8665fe6.png)
The text was updated successfully, but these errors were encountered: