mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-11 20:30:27 +02:00
net: Restrict period when cs_vNodes mutex is locked
This commit is contained in:
parent
f0b457212f
commit
a3d090d110
15
src/init.cpp
15
src/init.cpp
@ -200,20 +200,7 @@ void Shutdown(NodeContext& node)
|
|||||||
// Because these depend on each-other, we make sure that neither can be
|
// Because these depend on each-other, we make sure that neither can be
|
||||||
// using the other before destroying them.
|
// using the other before destroying them.
|
||||||
if (node.peerman) UnregisterValidationInterface(node.peerman.get());
|
if (node.peerman) UnregisterValidationInterface(node.peerman.get());
|
||||||
// Follow the lock order requirements:
|
if (node.connman) node.connman->Stop();
|
||||||
// * 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
StopTorControl();
|
StopTorControl();
|
||||||
|
|
||||||
|
@ -2636,8 +2636,9 @@ void CConnman::StopNodes()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close sockets
|
// Close sockets
|
||||||
LOCK(cs_vNodes);
|
std::vector<CNode*> nodes;
|
||||||
for (CNode* pnode : vNodes)
|
WITH_LOCK(cs_vNodes, nodes.swap(vNodes));
|
||||||
|
for (CNode* pnode : nodes)
|
||||||
pnode->CloseSocketDisconnect();
|
pnode->CloseSocketDisconnect();
|
||||||
for (ListenSocket& hListenSocket : vhListenSocket)
|
for (ListenSocket& hListenSocket : vhListenSocket)
|
||||||
if (hListenSocket.socket != INVALID_SOCKET)
|
if (hListenSocket.socket != INVALID_SOCKET)
|
||||||
@ -2645,13 +2646,12 @@ void CConnman::StopNodes()
|
|||||||
LogPrintf("CloseSocket(hListenSocket) failed with error %s\n", NetworkErrorString(WSAGetLastError()));
|
LogPrintf("CloseSocket(hListenSocket) failed with error %s\n", NetworkErrorString(WSAGetLastError()));
|
||||||
|
|
||||||
// clean up some globals (to help leak detection)
|
// clean up some globals (to help leak detection)
|
||||||
for (CNode* pnode : vNodes) {
|
for (CNode* pnode : nodes) {
|
||||||
DeleteNode(pnode);
|
DeleteNode(pnode);
|
||||||
}
|
}
|
||||||
for (CNode* pnode : vNodesDisconnected) {
|
for (CNode* pnode : vNodesDisconnected) {
|
||||||
DeleteNode(pnode);
|
DeleteNode(pnode);
|
||||||
}
|
}
|
||||||
vNodes.clear();
|
|
||||||
vNodesDisconnected.clear();
|
vNodesDisconnected.clear();
|
||||||
vhListenSocket.clear();
|
vhListenSocket.clear();
|
||||||
semOutbound.reset();
|
semOutbound.reset();
|
||||||
|
@ -100,7 +100,6 @@ void fuzz_target(FuzzBufferType buffer, const std::string& LIMIT_TO_MESSAGE_TYPE
|
|||||||
g_setup->m_node.peerman->SendMessages(&p2p_node);
|
g_setup->m_node.peerman->SendMessages(&p2p_node);
|
||||||
}
|
}
|
||||||
SyncWithValidationInterfaceQueue();
|
SyncWithValidationInterfaceQueue();
|
||||||
LOCK2(::cs_main, g_cs_orphans); // See init.cpp for rationale for implicit locking order requirement
|
|
||||||
g_setup->m_node.connman->StopNodes();
|
g_setup->m_node.connman->StopNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +80,5 @@ FUZZ_TARGET_INIT(process_messages, initialize_process_messages)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SyncWithValidationInterfaceQueue();
|
SyncWithValidationInterfaceQueue();
|
||||||
LOCK2(::cs_main, g_cs_orphans); // See init.cpp for rationale for implicit locking order requirement
|
|
||||||
g_setup->m_node.connman->StopNodes();
|
g_setup->m_node.connman->StopNodes();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user