Skip to content

Commit d31e5c1

Browse files
committed
Fix shutdown in case of errors during initialization
PR bitcoin#10286 introduced a few steps which are not robust to early shutdown in initialization. Stumbled upon this with bitcoin#11781, not sure if there are other scenarios that can trigger it, but it's harden against this in any case.
1 parent 26efc22 commit d31e5c1

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/init.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ void Shutdown()
193193

194194
// Because these depend on each-other, we make sure that neither can be
195195
// using the other before destroying them.
196-
UnregisterValidationInterface(peerLogic.get());
197-
if(g_connman) g_connman->Stop();
196+
if (peerLogic) UnregisterValidationInterface(peerLogic.get());
197+
if (g_connman) g_connman->Stop();
198198
peerLogic.reset();
199199
g_connman.reset();
200200

src/validationinterface.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ void CMainSignals::UnregisterBackgroundSignalScheduler() {
4949
}
5050

5151
void CMainSignals::FlushBackgroundCallbacks() {
52-
m_internals->m_schedulerClient.EmptyQueue();
52+
if (m_internals) {
53+
m_internals->m_schedulerClient.EmptyQueue();
54+
}
5355
}
5456

5557
void CMainSignals::RegisterWithMempoolSignals(CTxMemPool& pool) {
@@ -92,6 +94,9 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
9294
}
9395

9496
void UnregisterAllValidationInterfaces() {
97+
if (!g_signals.m_internals) {
98+
return;
99+
}
95100
g_signals.m_internals->BlockChecked.disconnect_all_slots();
96101
g_signals.m_internals->Broadcast.disconnect_all_slots();
97102
g_signals.m_internals->Inventory.disconnect_all_slots();

0 commit comments

Comments
 (0)