yyzybb537 / libgo

Go-style concurrency in C++11
MIT License
3.22k stars 758 forks source link

程序退出时会随机发生crash #150

Closed dearbird closed 5 years ago

dearbird commented 5 years ago

堆栈如下。 Stop() 能否实现成等待全部协程退出,或者额外提供该接口,以便实现优雅退出。

0 _M_find_before_node (code=3, k=, __n=3, this=0x9230f0 <co::HookHelper::getInstance()::obj+144>) at /usr/include/c++/4.8.2/bits/hashtable.h:1162

1162 node_type* __p = static_cast<node_type*>(__prev_p->_M_nxt); Missing separate debuginfos, use: debuginfo-install glibc-2.17-260.el7_6.3.x86_64 libgcc-4.8.5-36.el7.x86_64 libstdc++-4.8.5-36.el7.x86_64 (gdb) bt

0 _M_find_before_node (code=3, k=, __n=3, this=0x9230f0 <co::HookHelper::getInstance()::obj+144>) at /usr/include/c++/4.8.2/bits/hashtable.h:1162

1 _M_find_node (c=3, key=, __bkt=3, this=0x9230f0 <co::HookHelper::getInstance()::obj+144>) at /usr/include/c++/4.8.2/bits/hashtable.h:604

2 find (__k=, this=0x9230f0 <co::HookHelper::getInstance()::obj+144>) at /usr/include/c++/4.8.2/bits/hashtable.h:1025

3 find (__x=, this=0x9230f0 <co::HookHelper::getInstance()::obj+144>) at /usr/include/c++/4.8.2/bits/unordered_map.h:543

4 co::HookHelper::GetSlot (this=, fd=fd@entry=3) at /git/libgo/libgo/netio/unix/hook_helper.cpp:61

5 0x00000000006093b6 in co::HookHelper::OnClose (this=, fd=fd@entry=3) at /git/libgo/libgo/netio/unix/hook_helper.cpp:36

6 0x00000000005fb69f in fclose (fp=0x24db2f0) at /git/libgo/libgo/netio/unix/hook.cpp:1038

7 0x00000000006229b9 in __gcov_close ()

8 0x0000000000623571 in gcov_exit ()

9 0x00007fd73ab64b69 in __run_exit_handlers () from /lib64/libc.so.6

10 0x00007fd73ab64bb7 in exit () from /lib64/libc.so.6

11 0x00007fd73ab4d3dc in __libc_start_main () from /lib64/libc.so.6

12 0x00000000004ed7b9 in _start ()

yyzybb537 commented 5 years ago

已解决

dearbird commented 5 years ago

最新版本,仍会出现。 image

yyzybb537 commented 5 years ago

提供一下复现的代码吧

yyzybb537 commented 5 years ago

另外, Stop()等待全部协程退出是不可能的,这个接口就是设计成让主线程退出的

dearbird commented 5 years ago

有时间我尝试精简下代码,提供复现。 当前的场景应该是全局静态类,析构的时候有操作文件描述符(日志文件),而此时协程已经执行过Stop了。

yyzybb537 commented 5 years ago

这个要用户自己管理好才行。。。

dearbird commented 5 years ago

那个是写日志文件的文件描述符,不是网络文件描述符。

dearbird commented 5 years ago

日志类 是单件模式,类析构的时候close(fd), 这个应该很常见才对。

yyzybb537 commented 5 years ago

C++比较推荐的做法是:全局对象的析构里不要写逻辑

dearbird commented 5 years ago

将fclose的hook禁用,解决了。