From 3943b43a22cba5c8fee433ed565cd02d9a95e4a6 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 24 Jun 2025 12:34:42 +0800 Subject: [PATCH] [fix](be) Fix be aws-sdk-cpp memory leak * 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" otherwill 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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/be/src/runtime/exec_env_init.cpp b/be/src/runtime/exec_env_init.cpp index 30bf17e3424bff..22986cce191a2c 100644 --- a/be/src/runtime/exec_env_init.cpp +++ b/be/src/runtime/exec_env_init.cpp @@ -373,6 +373,8 @@ Status ExecEnv::_init(const std::vector& store_paths, _dict_factory = new doris::vectorized::DictionaryFactory(); _s_ready = true; + // Make aws-sdk-cpp InitAPI and ShutdownAPI called in the same thread + S3ClientFactory::instance(); return Status::OK(); }