Skip to content

Commit 64127b3

Browse files
committed
Merge #15280: gui: Fix shutdown order
0dd6a8c Check m_internals in UnregisterValidationInterface (João Barbosa) fd6d499 gui: Fix m_node.startShutdown() order (João Barbosa) 07b9aad gui: Expose BitcoinGUI::unsubscribeFromCoreSignals (João Barbosa) 60e190c gui: Fix WalletController deletion (João Barbosa) Pull request description: This PR consists in small fixes in order to have a clean shutdown from the GUI. Tree-SHA512: a9c641f202bc810698c4a39d5c5a1f54e54bdab098c412d65418879e00764a9db9f38383813914d591e24e097e49f177942b2ae6c57bba05dcc095e8a1d0b8f4
2 parents 2fbf6a5 + 0dd6a8c commit 64127b3

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/qt/bitcoin.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ BitcoinApplication::~BitcoinApplication()
218218
#ifdef ENABLE_WALLET
219219
delete paymentServer;
220220
paymentServer = nullptr;
221+
delete m_wallet_controller;
222+
m_wallet_controller = nullptr;
221223
#endif
222224
delete optionsModel;
223225
optionsModel = nullptr;
@@ -307,18 +309,20 @@ void BitcoinApplication::requestShutdown()
307309
qDebug() << __func__ << ": Requesting shutdown";
308310
startThread();
309311
window->hide();
312+
// Must disconnect node signals otherwise current thread can deadlock since
313+
// no event loop is running.
314+
window->unsubscribeFromCoreSignals();
315+
// Request node shutdown, which can interrupt long operations, like
316+
// rescanning a wallet.
317+
m_node.startShutdown();
318+
// Unsetting the client model can cause the current thread to wait for node
319+
// to complete an operation, like wait for a RPC execution to complate.
310320
window->setClientModel(nullptr);
311321
pollShutdownTimer->stop();
312322

313-
#ifdef ENABLE_WALLET
314-
delete m_wallet_controller;
315-
m_wallet_controller = nullptr;
316-
#endif
317323
delete clientModel;
318324
clientModel = nullptr;
319325

320-
m_node.startShutdown();
321-
322326
// Request shutdown from core thread
323327
Q_EMIT requestedShutdown();
324328
}

src/qt/bitcoingui.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class BitcoinGUI : public QMainWindow
9595
*/
9696
bool hasTrayIcon() const { return trayIcon; }
9797

98+
/** Disconnect core signals from GUI client */
99+
void unsubscribeFromCoreSignals();
100+
98101
protected:
99102
void changeEvent(QEvent *e);
100103
void closeEvent(QCloseEvent *event);
@@ -184,8 +187,6 @@ class BitcoinGUI : public QMainWindow
184187

185188
/** Connect core signals to GUI client */
186189
void subscribeToCoreSignals();
187-
/** Disconnect core signals from GUI client */
188-
void unsubscribeFromCoreSignals();
189190

190191
/** Update UI with latest network info from model. */
191192
void updateNetworkState();

src/validationinterface.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) {
107107
}
108108

109109
void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
110-
g_signals.m_internals->m_connMainSignals.erase(pwalletIn);
110+
if (g_signals.m_internals) {
111+
g_signals.m_internals->m_connMainSignals.erase(pwalletIn);
112+
}
111113
}
112114

113115
void UnregisterAllValidationInterfaces() {

0 commit comments

Comments
 (0)