starrocks/be/test/runtime
PengFei Li dfa190b48f
[UT] Fix memory leak in test LocalTabletsChannelTest::test_add_chunk_not_exist_tablet (#63218)
## Why I'm doing
- ASAN reported a memory leak in BE unit test `LocalTabletsChannelTest::test_add_chunk_not_exist_tablet`
  - Direct leak from `SecondaryReplicasWaiter::_send_replica_status_request()` allocating `ReusableClosure<PLoadReplicaStatusResult>`
```
=================================================================
==752488==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 792 byte(s) in 1 object(s) allocated from:
    #0 0x1a830f48 in operator new(unsigned long) (/root/celerdata/be/ut_build_ASAN/test/starrocks_test+0x1a830f48)
    #1 0x30153219 in starrocks::SecondaryReplicasWaiter::_send_replica_status_request(int) /root/celerdata/be/src/runtime/local_tablets_channel.cpp:1342
    #2 0x30152d52 in starrocks::SecondaryReplicasWaiter::_try_check_replica_status_on_primary(int) /root/celerdata/be/src/runtime/local_tablets_channel.cpp:1327
    #3 0x301520e3 in starrocks::SecondaryReplicasWaiter::wait() /root/celerdata/be/src/runtime/local_tablets_channel.cpp:1285
    #4 0x3013603a in starrocks::LocalTabletsChannel::add_chunk(starrocks::Chunk*, starrocks::PTabletWriterAddChunkRequest const&, starrocks::PTabletWriterAddBatchResult*, bool*) /root/celerdata/be/src/runtime/local_tablets_channel.cpp:380
    #5 0x1eefff41 in starrocks::LocalTabletsChannelTest_test_add_chunk_not_exist_tablet_Test::TestBody() /root/celerdata/be/test/runtime/local_tablets_channel_test.cpp:255
    #6 0x37d95703 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) googletest-release-1.10.0/googletest/src/gtest.cc:2433
    #7 0x37d95703 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) googletest-release-1.10.0/googletest/src/gtest.cc:2469
    #8 0x37d8856d in testing::Test::Run() googletest-release-1.10.0/googletest/src/gtest.cc:2508
    #9 0x37d8856d in testing::Test::Run() googletest-release-1.10.0/googletest/src/gtest.cc:2498
    #10 0x37d886cd in testing::TestInfo::Run() googletest-release-1.10.0/googletest/src/gtest.cc:2684
    #11 0x37d886cd in testing::TestInfo::Run() googletest-release-1.10.0/googletest/src/gtest.cc:2657
    #12 0x37d887b6 in testing::TestSuite::Run() googletest-release-1.10.0/googletest/src/gtest.cc:2816
    #13 0x37d887b6 in testing::TestSuite::Run() googletest-release-1.10.0/googletest/src/gtest.cc:2795
    #14 0x37d88d13 in testing::internal::UnitTestImpl::RunAllTests() googletest-release-1.10.0/googletest/src/gtest.cc:5338
    #15 0x37d88f23 in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) googletest-release-1.10.0/googletest/src/gtest.cc:2433
    #16 0x37d88f23 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) googletest-release-1.10.0/googletest/src/gtest.cc:2469
    #17 0x37d88f23 in testing::UnitTest::Run() googletest-release-1.10.0/googletest/src/gtest.cc:4925
    #18 0x1a893ea2 in RUN_ALL_TESTS() /var/local/thirdparty/installed/include/gtest/gtest.h:2473
    #19 0x1a87d8a4 in starrocks::init_test_env(int, char**) /root/celerdata/be/src/testutil/init_test_env.h:115
    #20 0x1a87e332 in main /root/celerdata/be/test/test_main.cpp:18
    #21 0x7f5813e29d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)

```
  
- Root cause:
  - The send path does `closure->ref()` twice (one for “self-hold”, one for “RPC-hold”).
  - The test does not register a sync-point callback for `LocalTabletsChannel::rpc::get_load_replica_status` to simulate the RPC, so no one calls `closure->Run()`, and the “RPC-hold” ref is never released.
  - The waiter’s release path only dropped one ref, leaving one outstanding reference and causing the leak.

## What I'm doing
- Introduce and use a sync-point primitive `TEST_SYNC_POINT_CALLBACK_OR_DEFAULT` with a default action, so tests without a registered callback still release the “RPC-hold” reference.
- At `LocalTabletsChannel::rpc::get_load_replica_status`, switch to a callback-with-default that calls `closure->Run()` when no test callback is installed. This balances the double `ref()` even in no-callback tests, while keeping production behavior unchanged.


Signed-off-by: PengFei Li <lpengfei2016@gmail.com>
Signed-off-by: Kevin Cai <kevin.cai@celerdata.com>
2025-09-25 09:26:01 +08:00
..
batch_write [Enhancement] Introduce TxnStateCache for merge commit sync mode (#55001) 2025-01-16 17:28:02 +08:00
memory [Refactor] Remove core arena mem allocator (#60221) 2025-06-25 13:21:52 +08:00
routine_load [Enhancement] Make routine load error msg more clear (#41306) 2024-03-20 19:13:30 +08:00
test_data [Feature] Stream load supports compression (#43732) 2024-04-29 20:03:47 +08:00
agg_state_desc_test.cpp [Refactor] Remove unused AnyValUtils (#51680) 2024-10-10 13:27:39 +08:00
arrow_result_writer_test.cpp [Feature]Support Arrow Flight SQL V1 (#57956) 2025-05-26 14:22:43 +08:00
buffer_control_block_test.cpp [Feature]Support Arrow Flight SQL V1 (#57956) 2025-05-26 14:22:43 +08:00
command_executor_test.cpp [Enhancement] Add scripting ability to BE (#20351) 2023-03-31 09:37:28 +08:00
data_stream_mgr_test.cpp [BugFix] Revert 'Avoid brpc communication when using local pass through' (#61631) 2025-08-07 14:26:33 +08:00
datetime_value_test.cpp [BugFix] fix memory UAF issue of parse_datetime function (#37833) 2023-12-27 18:34:45 +08:00
decimalv2_value_test.cpp [License] Change Elastic License to Apache License 2.0 (#14744) 2022-12-06 10:50:55 -08:00
decimalv3_test.cpp [Refactor] Move LargeIntValue from runtime to types (#53598) 2024-12-05 16:27:54 +08:00
diagnose_daemon_test.cpp [Enhancement] Capture stack trace if load meets brpc timeout (#56264) 2025-03-19 15:04:43 +08:00
exec_env_test.cpp [Refactor] Move mem_tracker to GlobalEnv (#27640) 2023-07-20 19:56:23 -07:00
external_scan_context_mgr_test.cpp [License] Change Elastic License to Apache License 2.0 (#14744) 2022-12-06 10:50:55 -08:00
fragment_mgr_test.cpp [BugFix] fix FragmentMgr dead lock in close() (#34181) 2023-11-02 16:16:48 +08:00
free_list_test.cpp [License] Change Elastic License to Apache License 2.0 (#14744) 2022-12-06 10:50:55 -08:00
http_result_writer_test.cpp [Feature] [Refactor] (COW Part2) Introduce Cow Column in StarRocks (#56287) 2025-03-06 11:10:58 +08:00
int128_arithmetic_ops_test.cpp [License] Change Elastic License to Apache License 2.0 (#14744) 2022-12-06 10:50:55 -08:00
kafka_consumer_pipe_test.cpp [Enhancement] Routine load records kafka partition/offset of dirty json data to the error log (#55772) 2025-05-07 13:41:35 +08:00
lake_tablets_channel_test.cpp [BugFix] Fix secondary replicas can continue waiting because of wrong timestamp (#62805) 2025-09-15 18:59:08 -07:00
large_int_value_test.cpp [Refactor] Move LargeIntValue from runtime to types (#53598) 2024-12-05 16:27:54 +08:00
load_channel_mgr_test.cpp [Enhancement] Move delta write open out of brpc worker (#56517) 2025-03-17 16:25:19 +08:00
load_channel_test.cpp [BugFix] Fix secondary replicas can continue waiting because of wrong timestamp (#62805) 2025-09-15 18:59:08 -07:00
load_fail_point_test.cpp [Enhancement] Add failpoints for load (#59518) 2025-06-10 23:01:20 +08:00
local_tablets_channel_test.cpp [UT] Fix memory leak in test LocalTabletsChannelTest::test_add_chunk_not_exist_tablet (#63218) 2025-09-25 09:26:01 +08:00
mem_pool_test.cpp [License] Change Elastic License to Apache License 2.0 (#14744) 2022-12-06 10:50:55 -08:00
mem_tracker_test.cpp [Refactor] Refactor the implement of dump mem_tracker tree. (#56121) 2025-02-21 17:17:47 +08:00
memory_scratch_sink_test.cpp [Refactor] Move all scanners to a single directory. (#62204) 2025-08-22 15:17:02 +08:00
memory_scratch_sink_test_issue_8676.cpp [Refactor] Move all scanners to a single directory. (#62204) 2025-08-22 15:17:02 +08:00
merge_cascade_test.cpp [Enhancement] optimize the performace for topn with large offset (#55886) 2025-02-27 16:51:30 +08:00
result_queue_mgr_test.cpp [Enhancement] Control parquet file size when general compression is applied (#47391) 2024-07-22 18:55:22 +08:00
routine_load_task_executor_test.cpp [Enhancement] Update routine load parameters (#25924) 2023-06-29 19:13:17 -07:00
small_file_mgr_test.cpp [Refactor] Add join/stop interface for HttpServer (#27734) 2023-07-22 11:32:56 +08:00
snapshot_loader_test.cpp [BugFix] Fix uncorrect new path for GIN file after restore (#45016) 2024-04-30 08:01:46 +00:00
sorted_chunks_merger_test.cpp [UT] clean clang compiler warnings (#58840) 2025-05-09 09:32:44 -07:00
stream_load_pipe_test.cpp [Enhancement] Routine load records kafka partition/offset of dirty json data to the error log (#55772) 2025-05-07 13:41:35 +08:00
time_bounded_stream_load_pipe_test.cpp [Feature] (batch write part3) Implement batch write on BE (#52556) 2024-11-14 14:29:13 +08:00
type_descriptor_test.cpp [Feature] Introduce Variant column definition (#61099) 2025-09-03 13:22:19 +08:00
user_function_cache_test.cpp [Enhancement] Make UDF URLs not have to use a specific ending (#60622) 2025-07-07 14:48:01 +08:00