Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt: Poll ShutdownTimer after init is done #12377

Merged
merged 1 commit into from
Feb 8, 2018

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Feb 7, 2018

The shutdown process has started in requestShutdown, but initialize will happily continue with initializeResult and start threads late in the shutdown progess. Deleting this running thread will crash the application according to the qt docs:
https://github.com/qt/qtbase/blob/e5033a5c9b769815112e922d0b224af860afd219/src/corelib/thread/qthread.cpp#L412-L415

Potential fix for #12372 (comment)

This reverts #11831 for now and hopefully restores the previous behaviour.

@maflcko maflcko added the GUI label Feb 7, 2018
@@ -467,8 +467,7 @@ void BitcoinApplication::initializeResult(bool success)
qDebug() << __func__ << ": Initialization result: " << success;
// Set exit result.
returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE;
if(success)
{
if (success && !ShutdownRequested()) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not convinced that this makes a difference at all. initialzeResult is emitted with the return value of appInitMain. The return value of appInitMain ("success") is supposed to be false when shutdown was requested during initialization.

Copy link
Member

Choose a reason for hiding this comment

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

It can make a difference if shutdown is requested between AppInitMain() returns and when this slot is executed, it's a QueuedConnection.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe

diff --git a/src/init.cpp b/src/init.cpp
index 50643ff96b..1f46e5e3d2 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1736,5 +1736,5 @@ bool AppInitMain()
     StartWallets(scheduler);
 #endif
 
-    return true;
+    return !ShutdownRequested();
 }

Copy link
Member

Choose a reason for hiding this comment

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

Indeed AppInitMain() return was changed recently in #11831, but I still think that is correct. IMO this change is also correct, it avoids initialization but the application should not crash without this change, so I don't agree it's a fix.

Copy link
Member

Choose a reason for hiding this comment

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

It can make a difference if shutdown is requested between AppInitMain() returns and when this slot is executed, it's a QueuedConnection.

Then after AppInitMain was successfully executed, a shutdown was requested (but not yet acted on), so I don't understand why going into qt initialization would crash. It could successfully shutdown after that.

But anyhow if this fixes a reproducible issue I'm okay with it, it's possible that there are interactions I don't follow.

Copy link
Member

@promag promag Feb 7, 2018

Choose a reason for hiding this comment

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

so I don't understand why going into qt initialization would crash

That's why I think this doesn't fix the problem, just avoids it.

Copy link
Member

Choose a reason for hiding this comment

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

That's good enough for rc3, though.

@laanwj laanwj added this to the 0.16.0 milestone Feb 7, 2018
@laanwj
Copy link
Member

laanwj commented Feb 7, 2018

If you have means to reproduce the underlying issue, what might also work is moving the shutdown detection to only start after the GUI side of the initialization. E.g. move

    pollShutdownTimer->start(200);

from BitcoinApplication::createWindow to BitcoinApplication::initializeResult (in the if(success)). This makes sure that no special action is undertaken if request shutdown is detected while initialization and avoids the race.

@maflcko maflcko changed the title qt: Avoid initialization during shutdown Revert "Always return true if AppInitMain got to the end" Feb 7, 2018
@maflcko maflcko changed the title Revert "Always return true if AppInitMain got to the end" qt: Poll ShutdownTimer after init is done Feb 7, 2018
@meshcollider
Copy link
Contributor

utACK 2222bf0

@maflcko
Copy link
Member Author

maflcko commented Feb 7, 2018

Changed to @laanwj suggestion

@laanwj
Copy link
Member

laanwj commented Feb 8, 2018

utACK 2222bf0

@laanwj laanwj merged commit 2222bf0 into bitcoin:master Feb 8, 2018
laanwj added a commit that referenced this pull request Feb 8, 2018
2222bf0 qt: Poll ShutdownTimer after init is done (MarcoFalke)

Pull request description:

  The shutdown process has started in `requestShutdown`, but initialize will happily continue with `initializeResult` and start threads late in the shutdown progess. Deleting this running thread will crash the application according to the qt docs:
  https://github.com/qt/qtbase/blob/e5033a5c9b769815112e922d0b224af860afd219/src/corelib/thread/qthread.cpp#L412-L415

  Potential fix for #12372 (comment)

  This reverts #11831 for now and hopefully restores the previous behaviour.

Tree-SHA512: 8e1706afe90ddf2d972aca12c12d4cb2a9a4f38646c59c5466fe5a1a67361896b93c43917d5ac283841ee2bcc62e6bb8dc2bc81dea9129c899b354e9a4ef241b
laanwj pushed a commit that referenced this pull request Feb 8, 2018
Github-Pull: #12377
Rebased-From: 2222bf0
Tree-SHA512: 575c10d9f043e2843616b989daaecfb357482445bc44b9f3af2fe0d891bb36b5ccb572f326703ea85291d56b9f6e8f4828496099b05889daea2277ad38aa0d0e
@maflcko maflcko deleted the Mf1802-qtInitShutdown branch February 12, 2018 13:18
HashUnlimited pushed a commit to chaincoin/chaincoin that referenced this pull request Mar 16, 2018
Github-Pull: bitcoin#12377
Rebased-From: 2222bf0
Tree-SHA512: 575c10d9f043e2843616b989daaecfb357482445bc44b9f3af2fe0d891bb36b5ccb572f326703ea85291d56b9f6e8f4828496099b05889daea2277ad38aa0d0e
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 15, 2019
Summary:
Backport of Core PR12377
bitcoin/bitcoin#12377

Test Plan: `ninja check check-functional`

Reviewers: deadalnix, Fabien, #bitcoin_abc, markblundeberg

Reviewed By: #bitcoin_abc, markblundeberg

Subscribers: teamcity, schancel

Differential Revision: https://reviews.bitcoinabc.org/D2545
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Mar 14, 2020
2222bf0 qt: Poll ShutdownTimer after init is done (MarcoFalke)

Pull request description:

  The shutdown process has started in `requestShutdown`, but initialize will happily continue with `initializeResult` and start threads late in the shutdown progess. Deleting this running thread will crash the application according to the qt docs:
  https://github.com/qt/qtbase/blob/e5033a5c9b769815112e922d0b224af860afd219/src/corelib/thread/qthread.cpp#L412-L415

  Potential fix for bitcoin#12372 (comment)

  This reverts bitcoin#11831 for now and hopefully restores the previous behaviour.

Tree-SHA512: 8e1706afe90ddf2d972aca12c12d4cb2a9a4f38646c59c5466fe5a1a67361896b93c43917d5ac283841ee2bcc62e6bb8dc2bc81dea9129c899b354e9a4ef241b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Mar 14, 2020
2222bf0 qt: Poll ShutdownTimer after init is done (MarcoFalke)

Pull request description:

  The shutdown process has started in `requestShutdown`, but initialize will happily continue with `initializeResult` and start threads late in the shutdown progess. Deleting this running thread will crash the application according to the qt docs:
  https://github.com/qt/qtbase/blob/e5033a5c9b769815112e922d0b224af860afd219/src/corelib/thread/qthread.cpp#L412-L415

  Potential fix for bitcoin#12372 (comment)

  This reverts bitcoin#11831 for now and hopefully restores the previous behaviour.

Tree-SHA512: 8e1706afe90ddf2d972aca12c12d4cb2a9a4f38646c59c5466fe5a1a67361896b93c43917d5ac283841ee2bcc62e6bb8dc2bc81dea9129c899b354e9a4ef241b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Mar 15, 2020
2222bf0 qt: Poll ShutdownTimer after init is done (MarcoFalke)

Pull request description:

  The shutdown process has started in `requestShutdown`, but initialize will happily continue with `initializeResult` and start threads late in the shutdown progess. Deleting this running thread will crash the application according to the qt docs:
  https://github.com/qt/qtbase/blob/e5033a5c9b769815112e922d0b224af860afd219/src/corelib/thread/qthread.cpp#L412-L415

  Potential fix for bitcoin#12372 (comment)

  This reverts bitcoin#11831 for now and hopefully restores the previous behaviour.

Tree-SHA512: 8e1706afe90ddf2d972aca12c12d4cb2a9a4f38646c59c5466fe5a1a67361896b93c43917d5ac283841ee2bcc62e6bb8dc2bc81dea9129c899b354e9a4ef241b
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Mar 6, 2021
c853471 init: shutdown and return early if ActivateBestChain() fails. (furszy)
1961163 qt: Poll ShutdownTimer after init is done (Marco)
21d56e7 [GUI] Topbar: don't try to poll for data if shutdown was requested. (furszy)

Pull request description:

  First commit was decoupled from #2131, the topbar staking status polling should not try to refresh data if shutdown was requested.
  Second commit is coming from bitcoin#12377.
  Third commit is starting the shutdown process and returning early (without starting the import thread) if the best chain cannot be activated during the node's initialization.

ACKs for top commit:
  random-zebra:
    utACK c853471
  Fuzzbawls:
    utACK c853471

Tree-SHA512: 8d5b289df0ba30d5f654b702e49b01127aa2470550d1313ed63022b0e6c737b3d092a50bd9caf759ea1308f20b6bab65a2a01ff89e7758e50826d389b257e16b
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 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.

None yet

4 participants