Skip to content

Commit

Permalink
fix: add check future object valid before wait on it
Browse files Browse the repository at this point in the history
  • Loading branch information
yyuuttaaoo committed Dec 23, 2024
1 parent f0ec524 commit 77c2fb4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions core/common/http/AsynCurlRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions core/common/timer/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
3 changes: 3 additions & 0 deletions core/monitor/SelfMonitorServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
6 changes: 3 additions & 3 deletions core/unittest/polling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
gtest_discover_tests(polling_preserved_dir_depth_unittest)

0 comments on commit 77c2fb4

Please sign in to comment.