From 4dad02d26417bea224cf2ab0597cd6189d8abda8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 27 Jan 2023 14:34:51 +0100 Subject: [PATCH] Fix `active_transactions` stop (#4080) --- nano/node/active_transactions.cpp | 15 ++++++++++----- nano/node/active_transactions.hpp | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 7eb1ff02..b07a6298 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -38,6 +38,11 @@ nano::active_transactions::~active_transactions () void nano::active_transactions::start () { + if (node.flags.disable_request_loop) + { + return; + } + debug_assert (!thread.joinable ()); thread = std::thread ([this] () { @@ -48,12 +53,12 @@ void nano::active_transactions::start () void nano::active_transactions::stop () { - stopped = true; - condition.notify_all (); - if (thread.joinable ()) { - thread.join (); + nano::lock_guard guard{ mutex }; + stopped = true; } + condition.notify_all (); + nano::join_or_pass (thread); clear (); } @@ -332,7 +337,7 @@ std::vector> nano::active_transactions::list_act void nano::active_transactions::request_loop () { nano::unique_lock lock{ mutex }; - while (!stopped && !node.flags.disable_request_loop) + while (!stopped) { auto const stamp_l = std::chrono::steady_clock::now (); diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index f99a8583..54a6b6f2 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -139,7 +139,7 @@ private: // Elections std::unordered_map> blocks; public: - explicit active_transactions (nano::node &, nano::confirmation_height_processor &); + active_transactions (nano::node &, nano::confirmation_height_processor &); ~active_transactions (); void start (); @@ -233,7 +233,7 @@ private: int active_hinted_elections_count{ 0 }; nano::condition_variable condition; - std::atomic stopped{ false }; + bool stopped{ false }; std::thread thread; friend class election;