Skip to content

Commit 4188f04

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 344937a commit 4188f04

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
@@ -232,7 +232,10 @@ void PrepareShutdown()
232232
#endif
233233
StopMapPort();
234234

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

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)