The dcd6eeb64adb2b532f5003cbb86ba65b3c08a87b commit (bitcoin/bitcoin#23288) introduced an intermittent failure in the psbt_wallet_tests/psbt_updater_test
unit test. See bitcoin/bitcoin#23368.
The test failure can be easily made reproducible with the following patch:
0--- a/src/scheduler.cpp
1+++ b/src/scheduler.cpp
2@@ -57,6 +57,8 @@ void CScheduler::serviceQueue()
3 Function f = taskQueue.begin()->second;
4 taskQueue.erase(taskQueue.begin());
5
6+ UninterruptibleSleep(100ms);
7+
8 {
9 // Unlock before calling f, so it can reschedule itself or another task
10 // without deadlocking:
This PR implements an idea which was mentioned in the comment:
Yes, as I said before this looks like a race where the wallet is deleted before stopping the scheduler: #23368 (comment)
IIRC, the order should be:
stop scheduler
delete wallet
delete scheduler
The second commit introduces a refactoring with no behavior change.
Fixes bitcoin/bitcoin#23368.