From 427d2e6aff623d68f386448af4e3ed2a4f00dde7 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 24 Jun 2025 16:37:45 +0800 Subject: [PATCH] [fix](be) Fix be aws-sdk-cpp memory leak (#52185) * https://github.com/aws/aws-sdk-cpp/pull/2314 * In the aws-sdk-cpp code, there is a suggestion: "Please call ShutdownAPI from the same thread from which InitAPI() has been called" otherwise it will cause memory leak. ``` ================================================================= ==3271527==ERROR: LeakSanitizer: detected memory leaks Direct leak of 216 byte(s) in 1 object(s) allocated from: #0 0x555f9ecf55ee in malloc (/mnt/ssd01/pipline/OpenSourceDoris/clusterEnv/P0/Cluster0/be/lib/doris_be+0x370815ee) (BuildId: 22b637395dd039b0) #1 0x555fd8e19bd7 in CRYPTO_zalloc (/mnt/ssd01/pipline/OpenSourceDoris/clusterEnv/P0/Cluster0/be/lib/doris_be+0x711a5bd7) (BuildId: 22b637395dd039b0) #2 0x555fda7c9d14 in aws_mqtt_library_init (/mnt/ssd01/pipline/OpenSourceDoris/clusterEnv/P0/Cluster0/be/lib/doris_be+0x72b55d14) (BuildId: 22b637395dd039b0) #3 0x555fda74ed1f in Aws::Crt::ApiHandle::ApiHandle(aws_allocator*) (/mnt/ssd01/pipline/OpenSourceDoris/clusterEnv/P0/Cluster0/be/lib/doris_be+0x72adad1f) (BuildId: 22b637395dd039b0) #4 0x555fa365f0c9 in doris::S3ClientFactory::instance() /root/doris/be/src/util/s3_util.cpp:188:28 #5 0x555f9f13b87b in doris::io::ObjClientHolder::init() /root/doris/be/src/io/fs/s3_file_system.cpp:78:15 #6 0x555f9f140eee in doris::io::S3FileSystem::init() /root/doris/be/src/io/fs/s3_file_system.cpp:182:21 ...... ``` --- be/src/runtime/exec_env_init.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/be/src/runtime/exec_env_init.cpp b/be/src/runtime/exec_env_init.cpp index 22a31c0cbe768a..bcb01a6336f2fa 100644 --- a/be/src/runtime/exec_env_init.cpp +++ b/be/src/runtime/exec_env_init.cpp @@ -93,6 +93,7 @@ #include "util/metrics.h" #include "util/parse_util.h" #include "util/pretty_printer.h" +#include "util/s3_util.h" #include "util/threadpool.h" #include "util/thrift_rpc_helper.h" #include "util/timezone_utils.h" @@ -308,6 +309,8 @@ Status ExecEnv::_init(const std::vector& store_paths, _s_ready = true; + // Make aws-sdk-cpp InitAPI and ShutdownAPI called in the same thread + S3ClientFactory::instance(); return Status::OK(); }