From 77c2fb43865195a0578156d75a056cc92b796aeb Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Mon, 23 Dec 2024 07:08:39 +0000 Subject: [PATCH] fix: add check future object valid before wait on it --- core/common/http/AsynCurlRunner.cpp | 3 +++ core/common/timer/Timer.cpp | 3 +++ core/monitor/SelfMonitorServer.cpp | 3 +++ core/unittest/polling/CMakeLists.txt | 6 +++--- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/common/http/AsynCurlRunner.cpp b/core/common/http/AsynCurlRunner.cpp index dccfa4c2e8..ee9e514137 100644 --- a/core/common/http/AsynCurlRunner.cpp +++ b/core/common/http/AsynCurlRunner.cpp @@ -39,6 +39,9 @@ bool AsynCurlRunner::Init() { void AsynCurlRunner::Stop() { mIsFlush = true; future_status s = mThreadRes.wait_for(chrono::seconds(1)); + if (!mThreadRes.valid()) { + return; + } if (s == future_status::ready) { LOG_INFO(sLogger, ("async curl runner", "stopped successfully")); } else { diff --git a/core/common/timer/Timer.cpp b/core/common/timer/Timer.cpp index 08ed7ed12c..8a99fc4348 100644 --- a/core/common/timer/Timer.cpp +++ b/core/common/timer/Timer.cpp @@ -34,6 +34,9 @@ void Timer::Stop() { mIsThreadRunning = false; } mCV.notify_one(); + if (!mThreadRes.valid()) { + return; + } future_status s = mThreadRes.wait_for(chrono::seconds(1)); if (s == future_status::ready) { LOG_INFO(sLogger, ("timer", "stopped successfully")); diff --git a/core/monitor/SelfMonitorServer.cpp b/core/monitor/SelfMonitorServer.cpp index d4a75e141a..42433dd928 100644 --- a/core/monitor/SelfMonitorServer.cpp +++ b/core/monitor/SelfMonitorServer.cpp @@ -64,6 +64,9 @@ void SelfMonitorServer::Stop() { mIsThreadRunning = false; } mStopCV.notify_one(); + if (!mThreadRes.valid()) { + return; + } future_status s = mThreadRes.wait_for(chrono::seconds(1)); if (s == future_status::ready) { LOG_INFO(sLogger, ("self-monitor", "stopped successfully")); diff --git a/core/unittest/polling/CMakeLists.txt b/core/unittest/polling/CMakeLists.txt index 80fe2a46c1..23843d1891 100644 --- a/core/unittest/polling/CMakeLists.txt +++ b/core/unittest/polling/CMakeLists.txt @@ -18,8 +18,8 @@ project(polling_unittest) # add_executable(polling_unittest PollingUnittest.cpp) # target_link_libraries(polling_unittest ${UT_BASE_TARGET}) -# add_executable(polling_preserved_dir_depth_unittest PollingPreservedDirDepthUnittest.cpp) -# target_link_libraries(polling_preserved_dir_depth_unittest ${UT_BASE_TARGET}) +add_executable(polling_preserved_dir_depth_unittest PollingPreservedDirDepthUnittest.cpp) +target_link_libraries(polling_preserved_dir_depth_unittest ${UT_BASE_TARGET}) include(GoogleTest) -# gtest_discover_tests(polling_preserved_dir_depth_unittest) \ No newline at end of file +gtest_discover_tests(polling_preserved_dir_depth_unittest) \ No newline at end of file