aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2018-08-08 14:02:54 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2018-08-08 15:19:00 +0200
commitdf9f71274645a917e2578c52a1c59745bce8112d (patch)
treefe57b634422a8cf8688b2363314d6363dae6fbfa
parent78dae8caccd82cfbfd76557f1fb7d7557c7b5edb (diff)
parentfaab63111d8f27335aa1f09c1a48da3be45135de (diff)
downloadbitcoin-df9f71274645a917e2578c52a1c59745bce8112d.tar.xz
Merge #13894: shutdown: Stop threads before resetting ptrs
faab63111d8f27335aa1f09c1a48da3be45135de shutdown: Stop threads before resetting ptrs (MarcoFalke) Pull request description: On shutdown some threads would continue to run after or during a pointer reset. This leads to occasional segfaults on shutdown. Fix this by resetting the smart pointers after all threads that might read from them have been stopped. This should fix: * A segfault in the txindex thread, that occurs when the txindex destructor is done, but the thread was not yet stopped (as this is done in the base index destructor) * A segfault in the scheduler thread, which dereferences conman. (e.g. CheckForStaleTipAndEvictPeers) Tree-SHA512: abbcf67fadd088e10fe8c384fadfb90bb115d5317145ccb5363603583b320efc18131e46384f55a9bc574969013dfcbd08c49e0d42c004ed7212eca193858ab2
-rw-r--r--src/init.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 21445929dc..5c29736913 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -209,11 +209,7 @@ void Shutdown()
// using the other before destroying them.
if (peerLogic) UnregisterValidationInterface(peerLogic.get());
if (g_connman) g_connman->Stop();
- peerLogic.reset();
- g_connman.reset();
- if (g_txindex) {
- g_txindex.reset();
- }
+ if (g_txindex) g_txindex->Stop();
StopTorControl();
@@ -222,6 +218,12 @@ void Shutdown()
threadGroup.interrupt_all();
threadGroup.join_all();
+ // After the threads that potentially access these pointers have been stopped,
+ // destruct and reset all to nullptr.
+ peerLogic.reset();
+ g_connman.reset();
+ g_txindex.reset();
+
if (g_is_mempool_loaded && gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
DumpMempool();
}