diff options
| author | Wladimir J. van der Laan <[email protected]> | 2020-04-06 20:38:30 +0200 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2020-04-06 21:06:09 +0200 |
| commit | c31bcaf203b5154117eee1cb2496dca2b7c3853d (patch) | |
| tree | 01512b259ab804255df1c35b746a12c644569b39 /src/init.cpp | |
| parent | Merge #18487: rpc: Fix rpcRunLater race in walletpassphrase (diff) | |
| parent | net: Add missing cs_vNodes lock (diff) | |
| download | discoin-c31bcaf203b5154117eee1cb2496dca2b7c3853d.tar.xz discoin-c31bcaf203b5154117eee1cb2496dca2b7c3853d.zip | |
Merge #18458: net: Add missing cs_vNodes lock
fa369651c5523f393e0bfcfa328b8e27006711aa net: Add missing cs_vNodes lock (MarcoFalke)
Pull request description:
Fixes #18457
ACKs for top commit:
promag:
Code review ACK fa369651c5523f393e0bfcfa328b8e27006711aa.
laanwj:
ACK fa369651c5523f393e0bfcfa328b8e27006711aa
Tree-SHA512: 60d7000f2f3d480bb0953ce27a0020763e7102da16a0006b619e0a236cfc33cbd4f83d870e9f0546639711cd877c1f9808d419184bbc153bb328885417e0066c
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 88caed9de..437e93409 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(); |