apache / brpc

brpc is an Industrial-grade RPC framework using C++ Language, which is often used in high performance system such as Search, Storage, Machine learning, Advertisement, Recommendation etc. "brpc" means "better RPC".
https://brpc.apache.org
Apache License 2.0
16.56k stars 3.98k forks source link

grpc H2UnsentResponse LeakSanitizer: detected memory leaks #2738

Open hpsdy opened 3 months ago

hpsdy commented 3 months ago

Describe the bug (描述bug) asan 压测,报h2协议brpc::policy::H2UnsentResponse::New内存泄漏

To Reproduce (复现方法) brpc1.8.0,h2:grpc协议。编译选项加上-fsanitize=address -fno-common,编译静态链接asan。

Expected behavior (期望行为) 期望不报任何异常错误。

Versions (各种版本) OS: Linux bae12e6ce16f 5.4.139-1.el7.elrepo.x86_64 #1 SMP Sat Aug 7 08:29:46 EDT 2021 x86_64 x86_64 x86_64 GNU/Linux Compiler: clang version 10.0.0-4ubuntu1 brpc: 1.8.0 protobuf: v3.20.0

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

截屏2024-08-19 上午11 38 13 截屏2024-08-19 上午11 38 24
hpsdy commented 2 months ago

有人么?

chenBright commented 2 months ago

https://github.com/apache/brpc/blob/d3c68546ec3973e03656c6129d8f17e0198a5824/src/brpc/policy/http2_rpc_protocol.cpp#L1687-L1691 https://github.com/apache/brpc/blob/d3c68546ec3973e03656c6129d8f17e0198a5824/src/brpc/policy/http2_rpc_protocol.cpp#L1672-L1678

在Socket里会调AppendAndDestroySelf回收的。

压测场景下,出现内存泄漏,应该不止泄漏几百bytes吧。是不是进程退出的时候,server还在处理请求呢?

hpsdy commented 2 months ago

进程没有退出,mem leak check是开了一个线程定时调用__lsan_do_recoverable_leak_check函数实现检查的。开启后,压测服务,一直会报这个case。不确定是asan检查机制识别不了这种内存释放,还是确实有泄漏。

wwbmmm commented 1 month ago

我记得asan是进程退出时才产出内存泄露报告的,如果进程没退出就检查,可能会不准确吧