diff --git a/src/init.cpp b/src/init.cpp index e92742be1d..cbae172cb2 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -254,20 +254,7 @@ void PrepareShutdown(NodeContext& node) // Because these depend on each-other, we make sure that neither can be // using the other before destroying them. if (node.peerman) UnregisterValidationInterface(node.peerman.get()); - // Follow the lock order requirements: - // * CheckForStaleTipAndEvictPeers locks cs_main before indirectly calling GetExtraFullOutboundCount - // which locks cs_vNodes. - // * ProcessMessage locks cs_main and g_cs_orphans before indirectly calling ForEachNode which - // locks cs_vNodes. - // * CConnman::Stop calls DeleteNode, which calls FinalizeNode, which locks cs_main and calls - // EraseOrphansFor, which locks g_cs_orphans. - // - // Thus the implicit locking order requirement is: (1) cs_main, (2) g_cs_orphans, (3) cs_vNodes. - if (node.connman) { - node.connman->StopThreads(); - LOCK2(::cs_main, ::g_cs_orphans); - node.connman->StopNodes(); - } + if (node.connman) node.connman->Stop(); StopTorControl(); diff --git a/src/net.cpp b/src/net.cpp index c884ed264c..67dee39d44 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -4301,13 +4301,15 @@ void CConnman::StopNodes() } } - { - LOCK(m_nodes_mutex); - - // Close sockets - for (CNode *pnode : m_nodes) - pnode->CloseSocketDisconnect(this); + // Delete peer connections. + std::vector nodes; + WITH_LOCK(m_nodes_mutex, nodes.swap(m_nodes)); + for (CNode *pnode : nodes) { + pnode->CloseSocketDisconnect(this); + DeleteNode(pnode); } + + // Close listening sockets. for (ListenSocket& hListenSocket : vhListenSocket) { if (hListenSocket.sock) { if (m_edge_trig_events && !m_edge_trig_events->RemoveSocket(hListenSocket.sock->Get())) { @@ -4316,12 +4318,6 @@ void CConnman::StopNodes() } } - // clean up some globals (to help leak detection) - std::vector nodes; - WITH_LOCK(m_nodes_mutex, nodes.swap(m_nodes)); - for (CNode* pnode : nodes) { - DeleteNode(pnode); - } for (CNode* pnode : m_nodes_disconnected) { DeleteNode(pnode); } diff --git a/src/test/fuzz/process_message.cpp b/src/test/fuzz/process_message.cpp index 7c042b5cb0..a5a59e3154 100644 --- a/src/test/fuzz/process_message.cpp +++ b/src/test/fuzz/process_message.cpp @@ -103,7 +103,6 @@ void fuzz_target(FuzzBufferType buffer, const std::string& LIMIT_TO_MESSAGE_TYPE } g_setup->m_node.peerman->SendMessages(&p2p_node); SyncWithValidationInterfaceQueue(); - LOCK2(::cs_main, g_cs_orphans); // See init.cpp for rationale for implicit locking order requirement g_setup->m_node.connman->StopNodes(); } diff --git a/src/test/fuzz/process_messages.cpp b/src/test/fuzz/process_messages.cpp index 938f189db1..5eb6e14925 100644 --- a/src/test/fuzz/process_messages.cpp +++ b/src/test/fuzz/process_messages.cpp @@ -76,6 +76,5 @@ FUZZ_TARGET_INIT(process_messages, initialize_process_messages) g_setup->m_node.peerman->SendMessages(&random_node); } SyncWithValidationInterfaceQueue(); - LOCK2(::cs_main, g_cs_orphans); // See init.cpp for rationale for implicit locking order requirement g_setup->m_node.connman->StopNodes(); }