HomePhabricator

Merge #13894: shutdown: Stop threads before resetting ptrs

Description

Merge #13894: shutdown: Stop threads before resetting ptrs

Summary:
PR13894 backport https://github.com/bitcoin/bitcoin/pull/13894/files
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)

Test Plan: make check

Reviewers: jasonbcox, Fabien, #bitcoin_abc, deadalnix

Reviewed By: jasonbcox, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D3123

Details