Skip to content

Commit fad8e7f

Browse files
author
MarcoFalke
committed
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 bitcoin/bitcoin#30967 (comment)
1 parent fa18586 commit fad8e7f

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/node/kernel_notifications.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class KernelNotifications : public kernel::Notifications
5858
bool m_shutdown_on_fatal_error{true};
5959

6060
Mutex m_tip_block_mutex;
61-
std::condition_variable m_tip_block_cv;
61+
std::condition_variable m_tip_block_cv GUARDED_BY(m_tip_block_mutex);
6262
//! The block for which the last blockTip notification was received for.
6363
uint256 m_tip_block GUARDED_BY(m_tip_block_mutex);
6464

src/rpc/server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ void StopRPC(const std::any& context)
305305
DeleteAuthCookie();
306306
node::NodeContext& node = EnsureAnyNodeContext(context);
307307
// The notifications interface doesn't exist between initialization step 4a and 7.
308-
if (node.notifications) node.notifications->m_tip_block_cv.notify_all();
308+
if (node.notifications) WITH_LOCK(node.notifications->m_tip_block_mutex, node.notifications->m_tip_block_cv.notify_all());
309309
LogDebug(BCLog::RPC, "RPC stopped.\n");
310310
});
311311
}

0 commit comments

Comments
 (0)