Skip to content

Commit

Permalink
Fix shutdown in case of errors during initialization
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
laanwj authored and furszy committed Dec 17, 2020
1 parent c2ea44f commit 59876a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/init.cpp
Expand Up @@ -232,7 +232,10 @@ void PrepareShutdown()
#endif
StopMapPort();

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

Expand Down
7 changes: 6 additions & 1 deletion src/validationinterface.cpp
Expand Up @@ -57,7 +57,9 @@ void CMainSignals::UnregisterBackgroundSignalScheduler() {
}

void CMainSignals::FlushBackgroundCallbacks() {
m_internals->m_schedulerClient.EmptyQueue();
if (m_internals) {
m_internals->m_schedulerClient.EmptyQueue();
}
}

CMainSignals& GetMainSignals()
Expand Down Expand Up @@ -93,6 +95,9 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn)

void UnregisterAllValidationInterfaces()
{
if (!g_signals.m_internals) {
return;
}
g_signals.m_internals->BlockFound.disconnect_all_slots();
g_signals.m_internals->BlockChecked.disconnect_all_slots();
g_signals.m_internals->Broadcast.disconnect_all_slots();
Expand Down

0 comments on commit 59876a4

Please sign in to comment.