diff options
author | MarcoFalke <falke.marco@gmail.com> | 2020-03-28 10:44:53 -0400 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2020-03-29 11:45:46 -0400 |
commit | fa369651c5523f393e0bfcfa328b8e27006711aa (patch) | |
tree | fb560aac582c7073afa51e95f9c375203cea3973 /src/init.cpp | |
parent | 210b533a114462473024c92a20a0765001abd45d (diff) | |
download | bitcoin-fa369651c5523f393e0bfcfa328b8e27006711aa.tar.xz |
net: Add missing cs_vNodes lock
Diffstat (limited to 'src/init.cpp')
-rw-r--r-- | src/init.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/init.cpp b/src/init.cpp index eb5329df66..7fac8b457c 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -197,7 +197,20 @@ 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.peer_logic) UnregisterValidationInterface(node.peer_logic.get()); - if (node.connman) node.connman->Stop(); + // Follow the lock order requirements: + // * CheckForStaleTipAndEvictPeers locks cs_main before indirectly calling GetExtraOutboundCount + // 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(); |