Skip to content
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

使用优雅退出时,cleanup_pthread清理keytable会coredump #1714

Closed
chenBright opened this issue Mar 8, 2022 · 0 comments · Fixed by #1884
Closed

使用优雅退出时,cleanup_pthread清理keytable会coredump #1714

chenBright opened this issue Mar 8, 2022 · 0 comments · Fixed by #1884

Comments

@chenBright
Copy link
Contributor

chenBright commented Mar 8, 2022

Describe the bug (描述bug)
使用优雅退出时,Server退出后,cleanup_pthread清理keytable时,进程会coredump。
core

To Reproduce (复现方法)

  1. 通过graceful_quit_on_sigterm打开优雅退出功能;
  2. 在service的回调函数中调用bthread_setspecific生成协程变量;
  3. 在main函数中,调用Server::RunUntilAskedToQuit
  4. 发起一个请求,等到请求结束后,发送SIGTERM或者SIGINT给brpc进程,让其执行优雅退出。

分析

  1. 在service的回调函数最前面调用bthread_setspecific生成协程变量,并通过 butil::thread_atexit(bthread::cleanup_pthread, kt)保存worker线程上第一个创建的keytable。请求结束后,该协程的keytable会回收到Server的keytable_pool的free_keytables中。
  2. 优雅退出时,Server::Join会清理keytable_pool的free_keytables,会delete第1步创建的keytable。worker线程退出时,bthread::cleanup_pthread也会delete这个keytable,造成double delete出coredump。

Expected behavior (期望行为)
优雅退出时能只清理pthread创建的keytable,bthread创建的keytable不需要在cleanup_pthread中清理,这些keytable会在return_keytable或者bthread_keytable_pool_destroy中清理。

Versions (各种版本)
OS: Ubuntu 16.04.4
Compiler: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.11)
brpc: 1.0.0
protobuf: 2

Additional context/screenshots (更多上下文/截图)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant