From fad8e7fba7bf2c523a191309d392cab79668264b Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Mon, 30 Sep 2024 11:53:05 +0200 Subject: [PATCH] bugfix: Mark m_tip_block_cv as guarded by m_tip_block_mutex This is not strictly required, but all places using m_tip_block_cv (except shutdown) already take the lock. The annotation makes it easier to catch potential deadlocks before review. Adding the missing lock to the shutdown sequence is a bugfix. An alternative would be to take the lock and release it before notifying, see https://github.com/bitcoin/bitcoin/pull/30967#discussion_r1778899716 --- src/node/kernel_notifications.h | 2 +- src/rpc/server.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node/kernel_notifications.h b/src/node/kernel_notifications.h index 71947e5f98c..12017f2b2c2 100644 --- a/src/node/kernel_notifications.h +++ b/src/node/kernel_notifications.h @@ -58,7 +58,7 @@ public: bool m_shutdown_on_fatal_error{true}; Mutex m_tip_block_mutex; - std::condition_variable m_tip_block_cv; + std::condition_variable m_tip_block_cv GUARDED_BY(m_tip_block_mutex); //! The block for which the last blockTip notification was received for. uint256 m_tip_block GUARDED_BY(m_tip_block_mutex); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 086f609ac3e..ab2135a9193 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -305,7 +305,7 @@ void StopRPC(const std::any& context) DeleteAuthCookie(); node::NodeContext& node = EnsureAnyNodeContext(context); // The notifications interface doesn't exist between initialization step 4a and 7. - if (node.notifications) node.notifications->m_tip_block_cv.notify_all(); + if (node.notifications) WITH_LOCK(node.notifications->m_tip_block_mutex, node.notifications->m_tip_block_cv.notify_all()); LogDebug(BCLog::RPC, "RPC stopped.\n"); }); }