Skip to content

Commit 4268aba

Browse files
committed
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.
1 parent 3a4d1a2 commit 4268aba

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/net.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,9 +3631,11 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) const
36313631
bool CConnman::DisconnectNode(const std::string& strNode)
36323632
{
36333633
LOCK(m_nodes_mutex);
3634-
if (CNode* pnode = FindNode(strNode)) {
3635-
LogDebug(BCLog::NET, "disconnect by address%s match, %s", (fLogIPs ? strprintf("=%s", strNode) : ""), pnode->DisconnectMsg(fLogIPs));
3636-
pnode->fDisconnect = true;
3634+
auto it = std::ranges::find_if(m_nodes, [&strNode](CNode* node) { return node->m_addr_name == strNode; });
3635+
if (it != m_nodes.end()) {
3636+
CNode* node{*it};
3637+
LogDebug(BCLog::NET, "disconnect by address%s match, %s", (fLogIPs ? strprintf("=%s", strNode) : ""), node->DisconnectMsg(fLogIPs));
3638+
node->fDisconnect = true;
36373639
return true;
36383640
}
36393641
return false;

0 commit comments

Comments
 (0)