diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2018-08-08 14:02:54 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2018-08-08 15:19:00 +0200 |
commit | df9f71274645a917e2578c52a1c59745bce8112d (patch) | |
tree | fe57b634422a8cf8688b2363314d6363dae6fbfa /src | |
parent | 78dae8caccd82cfbfd76557f1fb7d7557c7b5edb (diff) | |
parent | faab63111d8f27335aa1f09c1a48da3be45135de (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/init.cpp | 12 |
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(); } |