chenBright opened a new issue #1714: URL: https://github.com/apache/incubator-brpc/issues/1714
**Describe the bug (描述bug)** 使用优雅退出时,Server退出后,调用bthread_stop_world停止协程和worker线程,在回收worker线程,cleanup_pthread清理keytable时,进程会coredump。  **To Reproduce (复现方法)** 1. 通过`graceful_quit_on_sigterm`打开优雅退出功能; 2. 在service的回调函数中调用`bthread_setspecific`生成协程变量; 3. 在main函数中,`Server::RunUntilAskedToQuit`之后调用`bthread::bthread_stop_world`函数,停止协程和worker线程。 4. 发起一个请求,等到请求结束后,发送SIGTERM或者SIGINT给brpc进程,让其执行优雅退出。 **分析** 1. 请求结束后,该协程的keytable会回收到Server的keytable_pool的free_keytables中。优雅退出时,`Server::Join`会清理keytable_pool的free_keytables。 2. 调用`bthread_setspecific`生成协程变量,并通过` butil::thread_atexit(bthread::cleanup_pthread, kt)`保存worker线程上第一个创建的keytable。等到worker线程被回收时,会delete这个keytable。 3. 以上会造成double free,从而造成程序coredump。 [这个commit](https://github.com/apache/incubator-brpc/commit/72c5135401c6420c77c8a614d95f10082809e27d?diff=split)修改前就不会有这个问题。 **Expected behavior (期望行为)** bthread_stop_world停止协程和worker线程后能正常清理keytable和正常优雅退出。 **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 (更多上下文/截图)** -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
