Skip to content

Commit 7d688a3

Browse files
laanwjfurszy
authored andcommitted
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 d9ab10f commit 7d688a3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/init.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,10 @@ void PrepareShutdown()
231231
#endif
232232
StopMapPort();
233233

234-
UnregisterValidationInterface(peerLogic.get());
234+
// Because these depend on each-other, we make sure that neither can be
235+
// using the other before destroying them.
236+
if (peerLogic) UnregisterValidationInterface(peerLogic.get());
237+
if (g_connman) g_connman->Stop();
235238
peerLogic.reset();
236239
g_connman.reset();
237240

src/validationinterface.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ void CMainSignals::UnregisterBackgroundSignalScheduler() {
5757
}
5858

5959
void CMainSignals::FlushBackgroundCallbacks() {
60-
m_internals->m_schedulerClient.EmptyQueue();
60+
if (m_internals) {
61+
m_internals->m_schedulerClient.EmptyQueue();
62+
}
6163
}
6264

6365
CMainSignals& GetMainSignals()
@@ -93,6 +95,9 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn)
9395

9496
void UnregisterAllValidationInterfaces()
9597
{
98+
if (!g_signals.m_internals) {
99+
return;
100+
}
96101
g_signals.m_internals->BlockFound.disconnect_all_slots();
97102
g_signals.m_internals->BlockChecked.disconnect_all_slots();
98103
g_signals.m_internals->Broadcast.disconnect_all_slots();

0 commit comments

Comments
 (0)