线程池的线程回收退时core在brpc https://github.com/apache/brpc/issues/1606
Describe the bug (描述bug) 使用jni加载brpc.so时报pthread_mutex_lock未定义, 使用export LD_PRELOAD=/usr/lib64/libbrpc.so 解决了加载的问题,但java线程在退出时core掉了。
To Reproduce (复现方法) 使用jni加载brpc.so 并在java中使用线程,观察 线程退出时会不会产生core
Expected behavior (期望行为) java线程正常退出
Versions (各种版本) OS: Compiler: brpc: protobuf:
Additional context/screenshots (更多上下文/截图) #0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51 https://github.com/apache/brpc/issues/1 0x00007f259f32ff95 in __GI_abort () at abort.c:79 https://github.com/apache/brpc/issues/2 0x00007f259b95be09 in os::abort(bool) () from /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el7_9.x86_64/jre/lib/amd64/server/libjvm.so https://github.com/apache/brpc/issues/3 0x00007f259bb8367a in VMError::report_and_die() () from /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el7_9.x86_64/jre/lib/amd64/server/libjvm.so https://github.com/apache/brpc/issues/4 0x00007f259b965fb5 in JVM_handle_linux_signal () from /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el7_9.x86_64/jre/lib/amd64/server/libjvm.so https://github.com/apache/brpc/issues/5 0x00007f259b958fc8 in signalHandler(int, siginfo_t*, void*) () from /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el7_9.x86_64/jre/lib/amd64/server/libjvm.so https://github.com/apache/brpc/issues/6 https://github.com/apache/brpc/pull/7 0x0000000000000000 in ?? () https://github.com/apache/brpc/issues/8 0x00007f25a008b80a in ~ThreadExitHelper (this=0x55d1764021e0, __in_chrg=) at src/brpc/src/butil/thread_local.cpp:41 https://github.com/apache/brpc/pull/9 butil::detail::delete_thread_exit_helper (arg=0x55d1764021e0) at src/brpc/src/butil/thread_local.cpp:80 https://github.com/apache/brpc/pull/10 0x00007f259fce5a78 in __nptl_deallocate_tsd () at pthread_create.c:301 https://github.com/apache/brpc/issues/11 0x00007f259fce698d in __nptl_deallocate_tsd () at ../sysdeps/nptl/futex-internal.h:82 https://github.com/apache/brpc/issues/12 start_thread (arg=0x7f24d3031700) at pthread_create.c:488 https://github.com/apache/brpc/issues/13 0x00007f259f3eebef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
(gdb) p pd->specific $3 = {0x7f24d3031a10, 0x0 <repeats 31 times>} (gdb) p pd->specific[0] $4 = {seq = 1, data = 0x0} (gdb) p __pthread_keys $5 = {{seq = 1, destr = 0x7f25a008b750 butil::detail::delete_thread_exit_helper(void*)}, {seq = 1, destr = 0x7f259f6b7340 <free_key_mem>}, {seq = 1, destr = 0x7f259b958bb0 <restore_thread_pointer(void)>}, {seq = 1, destr = 0x7f25266e0420 <on_thread_exit>}, {seq = 0, destr = 0x0} <repeats 1020 times>}
我在butil/thread_local.cpp 文件 里面 注册和除 的时候 都 加了日志,但是只有删除 的时候 打印了日志: thread 0x7f24d3031700 key 0 delete 0x55d1764021e0 thread 0x7f24d3031700 fns 0x55d1764021e0 num 8737345935673 thread 0x7f25266d7270 first 0x7f25266d74c0 second (nil) thread 0x0 first 0x100000000 second (nil)
删除ThreadExitHelper传入的内存是有问题的。这个问题和brpc.so的加载 顺序有关系 。 开始是和 https://github.com/apache/brpc/issues/2266 这个问题有关,加载libbrpc.so会报 pthread_mutex_lock 未定义 通过https://github.com/apache/brpc/issues/1086 这个方法,export LD_PRELOAD=/usr/lib64/libbrpc.so 解决了问题 但是在java线程退出的时候 就直接 core掉了。 我现在按照 https://github.com/apache/brpc/issues/2266 这个解决方案,将pthread_mutex_lock/unock和init_sys_mutex_lock函数注释 掉。然后去掉export LD_PRELOAD=/usr/lib64/libbrpc.so是没有问题的。没搞清楚为什么使用export LD_PRELOAD=/usr/lib64/libbrpc.so 会有问题。
怀疑还是和系统 的pthread函数冲突有关系 。