mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Merge bitcoin/bitcoin#21563: net: Restrict period when cs_vNodes mutex is locked
8c8237a4a1net, refactor: Fix style in CConnman::StopNodes (Hennadii Stepanov)229ac1892dnet: Combine two loops into one, and update comments (Hennadii Stepanov)a3d090d110net: Restrict period when cs_vNodes mutex is locked (Hennadii Stepanov) Pull request description: This PR restricts the period when the `cs_vNodes` mutex is locked, prevents the only case when `cs_vNodes` could be locked before the `::cs_main`. This change makes the explicit locking of recursive mutexes in the explicit order redundant. ACKs for top commit: jnewbery: utACK8c8237a4a1vasild: ACK8c8237a4a1ajtowns: utACK8c8237a4a1- logic seems sound MarcoFalke: review ACK8c8237a4a1👢 Tree-SHA512: a8277924339622b188b12d260a100adf5d82781634cf974320cf6007341f946a7ff40351137c2f5369aed0d318f38aac2d32965c9b619432440d722a4e78bb73
This commit is contained in:
15
src/init.cpp
15
src/init.cpp
@@ -194,20 +194,7 @@ void Shutdown(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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user