From 4268abae1a1d06f2c4bd26b85b3a491719217fae Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Tue, 22 Apr 2025 12:32:34 +0200 Subject: [PATCH] net: avoid recursive m_nodes_mutex lock in DisconnectNode() Have `CConnman::DisconnectNode()` iterate `m_nodes` itself instead of using `FindNode()`. This avoids recursive mutex lock and drops the only caller of `FindNode()` which used the return value for something else than a boolean found/notfound. --- src/net.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index e8d2819a88e..6e95d6a3736 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -3631,9 +3631,11 @@ void CConnman::GetNodeStats(std::vector& vstats) const bool CConnman::DisconnectNode(const std::string& strNode) { LOCK(m_nodes_mutex); - if (CNode* pnode = FindNode(strNode)) { - LogDebug(BCLog::NET, "disconnect by address%s match, %s", (fLogIPs ? strprintf("=%s", strNode) : ""), pnode->DisconnectMsg(fLogIPs)); - pnode->fDisconnect = true; + auto it = std::ranges::find_if(m_nodes, [&strNode](CNode* node) { return node->m_addr_name == strNode; }); + if (it != m_nodes.end()) { + CNode* node{*it}; + LogDebug(BCLog::NET, "disconnect by address%s match, %s", (fLogIPs ? strprintf("=%s", strNode) : ""), node->DisconnectMsg(fLogIPs)); + node->fDisconnect = true; return true; } return false;