Skip to content

Commit 5091ab5

Browse files
laanwjPastaPastaPasta
authored andcommitted
Merge bitcoin#11783: Fix shutdown in case of errors during initialization
d31e5c1 Fix shutdown in case of errors during initialization (Wladimir J. van der Laan) Pull request description: 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 good to harden against this in any case. E.g. ``` $ src/bitcoind -debuglogfile=/dfdf Error: Could not open debug log file /dfdf Program received signal SIGSEGV, Segmentation fault. UnregisterValidationInterface (pwalletIn=0x0) at /.../bitcoin/src/validationinterface.cpp:82 82 g_signals.m_internals->BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2)); (gdb) bt #0 UnregisterValidationInterface (pwalletIn=0x0) at /.../bitcoin/src/validationinterface.cpp:82 #1 0x00005555555a11fc in Shutdown () at /.../bitcoin/src/init.cpp:196 #2 0x00005555555961cc in AppInit (argc=<optimized out>, argv=<optimized out>) at /.../bitcoin/src/bitcoind.cpp:183 #3 0x0000555555596249 in main (argc=0, argv=0x555555ecf200) at /.../bitcoin/src/bitcoind.cpp:19 ``` Tree-SHA512: 7dd9570a9803514a17781bfadf1edde47e96df4e852cce2f423cab422e005fb94d44e777af1a6ea5167b04a4d889e848ae7a61a7e0e94232247ddea32ee70fc8
1 parent 4f2fcbd commit 5091ab5

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
@@ -243,8 +243,8 @@ void PrepareShutdown()
243243

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

src/validationinterface.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ void CMainSignals::UnregisterBackgroundSignalScheduler() {
5454
}
5555

5656
void CMainSignals::FlushBackgroundCallbacks() {
57-
m_internals->m_schedulerClient.EmptyQueue();
57+
if (m_internals) {
58+
m_internals->m_schedulerClient.EmptyQueue();
59+
}
5860
}
5961

6062
CMainSignals& GetMainSignals()
@@ -103,6 +105,9 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
103105
}
104106

105107
void UnregisterAllValidationInterfaces() {
108+
if (!g_signals.m_internals) {
109+
return;
110+
}
106111
g_signals.m_internals->BlockChecked.disconnect_all_slots();
107112
g_signals.m_internals->Broadcast.disconnect_all_slots();
108113
g_signals.m_internals->Inventory.disconnect_all_slots();

0 commit comments

Comments
 (0)