Skip to content

Conversation

@promag
Copy link
Contributor

@promag promag commented Jan 29, 2019

This PR consists in small fixes in order to have a clean shutdown from the GUI.

Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK, but paging @Empact, @laanwj, @LeandroRocha84 #13217 and @MarcoFalke #13880 as QT shutdown connoisseurs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this move, either in a comment or in the commit message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The m_wallet_controller must be deleted after window (because it's used there).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I meant in a source code comment though :-) The shutdown logic keeps causing headaches, so there's no such thing as too much documentation I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add if I need to update this branch for other reasons, otherwise I'll improve the shutdown even further with more comments. From testing this is enough to get #15153 working without problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: might as well merge this with the next commit, which explains why this exposure is needed..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good to have move only separate?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to combine exposing a new interface with adding uses for it - I think of it as an expression of the outside-in development principle, the use comes before the changes it motivates/justifies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why you moved startShutdown(); up? Is it because setClientModel could be blocking and so you can to get this over with first?

Copy link
Contributor Author

@promag promag Jan 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling setClientModel(nullptr) hits:

if (!model) {
// Client model is being set to 0, this means shutdown() is about to be called.
thread.quit();
thread.wait();
}

and if there is a rescan in progress it blocks until the rescan completes. Calling m_node.startShutdown(); causes the rescan to interrupt.

@jonasschnelli
Copy link
Contributor

utACK 870e35c30c0286e729a55fc343ab9b1945619699

@hebasto
Copy link
Member

hebasto commented Jan 30, 2019

tACK 870e35c30c0286e729a55fc343ab9b1945619699 (Linux) modulo #15280 (comment) and #15280 (comment).

@Empact
Copy link
Contributor

Empact commented Jan 30, 2019

This could benefit from adding "why" to each commit message, which currently only describe what is done. Will be easier to evaluate now and interpret in the future with that info.

@promag promag force-pushed the 2019-01-gui-shutdown branch 2 times, most recently from df785ea to 0b53bf9 Compare January 30, 2019 22:56
@promag
Copy link
Contributor Author

promag commented Jan 30, 2019

Improved each commit message (hope it is now more clear).

A good test case to check with and without this PR is:

  1. add a MilliSleep to the rescan loop, after the while:

    bitcoin/src/wallet/wallet.cpp

    Lines 1659 to 1660 in cb77dc8

    while (block_height && !fAbortRescan && !ShutdownRequested()) {
    if (*block_height % 100 == 0 && progress_end - progress_begin > 0.0) {
  2. launch with -nowallet -rescan
  3. call loadwallet a_wallet_with_some_transactions in the console window
  4. close the application

@DrahtBot
Copy link
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #15153 (gui: Add Open Wallet menu by promag)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@Empact
Copy link
Contributor

Empact commented Jan 31, 2019

utACK 0b53bf9

Thanks for expanding those commit messages. Should we also guard in RegisterValidationInterface? It's the only other unguarded access to g_signals.m_internals.

@promag
Copy link
Contributor Author

promag commented Feb 1, 2019

@Empact different PR IMO. I had a commit to guard it with cs_main but removed since it's not GUI related.

The wallet controller instanced must be deleted after the window instance
since it is used there.
Move only change that makes unsubscribeFromCoreSignals public. It must be
called if the event loop is not running otherwise core signals handlers
can deadlock.
This change forwards the shutdown request on the GUI (close the
application for instace) to the node as soon as possible. This way the
GUI doesn't have to wait for long operations to complete (rescan the
wallet for instance), instead those operations detect the shutdown
request and abort/interrupt.
When a wallet is created it is registered in the validation interface (in
CWallet::CreateWalletFromFile) but it is not immediately added to the
wallets list. If a shutdown is requested before AddWallet (case more
evident when -rescan is set) then m_internals can be released (in
Shutdown -> UnregisterBackgroundSignalScheduler) before the wallet and
then ReleaseWallet would call UnregisterValidationInterface with
m_internals already released.
@promag promag force-pushed the 2019-01-gui-shutdown branch from 0b53bf9 to 0dd6a8c Compare February 3, 2019 22:24
@laanwj
Copy link
Member

laanwj commented Feb 4, 2019

utACK 0dd6a8c

pull bot pushed a commit to jaschadub/bitcoin that referenced this pull request Feb 4, 2019
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
@laanwj laanwj merged commit 0dd6a8c into bitcoin:master Feb 4, 2019
@promag promag deleted the 2019-01-gui-shutdown branch February 4, 2019 11:56
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 3, 2020
Summary:
 * gui: Fix WalletController deletion

The wallet controller instanced must be deleted after the window instance
since it is used there.

 * gui: Expose BitcoinGUI::unsubscribeFromCoreSignals

Move only change that makes unsubscribeFromCoreSignals public. It must be
called if the event loop is not running otherwise core signals handlers
can deadlock.

 * gui: Fix m_node.startShutdown() order

This change forwards the shutdown request on the GUI (close the
application for instace) to the node as soon as possible. This way the
GUI doesn't have to wait for long operations to complete (rescan the
wallet for instance), instead those operations detect the shutdown
request and abort/interrupt.

 * Check m_internals in UnregisterValidationInterface

When a wallet is created it is registered in the validation interface (in
CWallet::CreateWalletFromFile) but it is not immediately added to the
wallets list. If a shutdown is requested before AddWallet (case more
evident when -rescan is set) then m_internals can be released (in
Shutdown -> UnregisterBackgroundSignalScheduler) before the wallet and
then ReleaseWallet would call UnregisterValidationInterface with
m_internals already released.

This is a backport of Core [[bitcoin/bitcoin#15280 | PR15280]]

Test Plan:
  ninja all check-all

Run bitcoin-qt on win64 and verify it shuts down properly.

Reviewers: #bitcoin_abc, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D6344
ftrader pushed a commit to bitcoin-cash-node/bitcoin-cash-node that referenced this pull request Aug 17, 2020
Summary:
 * gui: Fix WalletController deletion

The wallet controller instanced must be deleted after the window instance
since it is used there.

 * gui: Expose BitcoinGUI::unsubscribeFromCoreSignals

Move only change that makes unsubscribeFromCoreSignals public. It must be
called if the event loop is not running otherwise core signals handlers
can deadlock.

 * gui: Fix m_node.startShutdown() order

This change forwards the shutdown request on the GUI (close the
application for instace) to the node as soon as possible. This way the
GUI doesn't have to wait for long operations to complete (rescan the
wallet for instance), instead those operations detect the shutdown
request and abort/interrupt.

 * Check m_internals in UnregisterValidationInterface

When a wallet is created it is registered in the validation interface (in
CWallet::CreateWalletFromFile) but it is not immediately added to the
wallets list. If a shutdown is requested before AddWallet (case more
evident when -rescan is set) then m_internals can be released (in
Shutdown -> UnregisterBackgroundSignalScheduler) before the wallet and
then ReleaseWallet would call UnregisterValidationInterface with
m_internals already released.

This is a backport of Core [[bitcoin/bitcoin#15280 | PR15280]]

Test Plan:
  ninja all check-all

Run bitcoin-qt on win64 and verify it shuts down properly.

Reviewers: #bitcoin_abc, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D6344
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Aug 2, 2021
…ionInterface

When a wallet is created it is registered in the validation interface (in
CWallet::CreateWalletFromFile) but it is not immediately added to the
wallets list. If a shutdown is requested before AddWallet (case more
evident when -rescan is set) then m_internals can be released (in
Shutdown -> UnregisterBackgroundSignalScheduler) before the wallet and
then ReleaseWallet would call UnregisterValidationInterface with
m_internals already released.
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Aug 11, 2021
kwvg pushed a commit to kwvg/dash that referenced this pull request Aug 12, 2021
UdjinM6 added a commit to dashpay/dash that referenced this pull request Aug 13, 2021
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 21, 2021
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants