Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented Aug 4, 2018

The application would either quit or std::exit on failure and not even try a shutdown.

Note that bitcoind does a Interrupt and Shutdown in case the initialization fails or an exception is caught. So just do the same for the gui.

@maflcko maflcko added the GUI label Aug 4, 2018
@maflcko
Copy link
Member Author

maflcko commented Aug 4, 2018

Might fix #12337

@laanwj
Copy link
Member

laanwj commented Aug 7, 2018

Concept ACK

Copy link
Contributor

@promag promag 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Add try/catch here instead? Otherwise should fix indentation above.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could log something? Same below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any suggestions? Note that I'd rather not write to the debug.log, since that might be the cause of the exception.

Copy link
Member

Choose a reason for hiding this comment

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

I tend to agree that blanket-ignoring exceptions is very bad. Even printing to stderr would be better to at least have a potential chance of someone diagnosing of seeing the error!

Copy link
Member Author

Choose a reason for hiding this comment

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

The gui is not always started from the command line, so that would be missed often as well. But I guess I could add it.

@jonasschnelli
Copy link
Contributor

Concept ACK

@maflcko
Copy link
Member Author

maflcko commented Aug 22, 2018

Added a commit to print the exception (per common request)

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

This PR is confusing and I think it is trying to do too many things. It would be easier to understand smaller PRs targeted at specific, reproducible problems.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it is right to call appShutdown() here because it should be covered by return quit(); below. quit should cause the first application loop to quit, which should trigger requestShutdown():

bitcoin/src/qt/bitcoin.cpp

Lines 718 to 720 in 59ecacf

app.exec();
app.requestShutdown();
app.exec();

which should trigger requestedShutdown():

bitcoin/src/qt/bitcoin.cpp

Lines 404 to 431 in 59ecacf

void BitcoinApplication::requestShutdown()
{
// Show a simple window indicating shutdown status
// Do this first as some of the steps may take some time below,
// for example the RPC console may still be executing a command.
shutdownWindow.reset(ShutdownWindow::showShutdownWindow(window));
qDebug() << __func__ << ": Requesting shutdown";
startThread();
window->hide();
window->setClientModel(0);
pollShutdownTimer->stop();
#ifdef ENABLE_WALLET
window->removeAllWallets();
for (WalletModel *walletModel : m_wallet_models) {
delete walletModel;
}
m_wallet_models.clear();
#endif
delete clientModel;
clientModel = 0;
m_node.startShutdown();
// Request shutdown from core thread
Q_EMIT requestedShutdown();
}

which should trigger BitcoinCore::shutdown:

connect(this, &BitcoinApplication::requestedShutdown, executor, &BitcoinCore::shutdown);

which already calls appShutdown():

bitcoin/src/qt/bitcoin.cpp

Lines 268 to 281 in 59ecacf

void BitcoinCore::shutdown()
{
try
{
qDebug() << __func__ << ": Running Shutdown in thread";
m_node.appShutdown();
qDebug() << __func__ << ": Shutdown finished";
Q_EMIT shutdownResult();
} catch (const std::exception& e) {
handleRunawayException(&e);
} catch (...) {
handleRunawayException(nullptr);
}
}

The shutdown process is definitely overcomplicated and should be simplified. I think a good direction would be to stop calling QApplication::quit during shutdown and instead just call it after. So Qt shutdown would just immediately follow bitcoin shutdown instead of being mingled with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could call PrintExceptionContinue(nullptr) in these empty catches. boost::current_exception_diagnostic_information() could also be used to add more detail.

Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem like the right place to be calling appShutdown. The emit below is supposed to trigger BitcoinApplication::handleRunawayException:

connect(executor, &BitcoinCore::runawayException, this, &BitcoinApplication::handleRunawayException);

which is supposed to show an error dialog and then exit:

bitcoin/src/qt/bitcoin.cpp

Lines 523 to 527 in 59ecacf

void BitcoinApplication::handleRunawayException(const QString &message)
{
QMessageBox::critical(0, "Runaway exception", BitcoinGUI::tr("A fatal error occurred. Bitcoin can no longer continue safely and will quit.") + QString("\n\n") + message);
::exit(EXIT_FAILURE);
}

If you shut down in BitcoinCore::handleRunawayException, it seems like this is going to delay the dialog from showing up, and maybe even prevent it from being seen by the user. But if this is really an improvement, it would be good to have a comment explaining what the shutdown sequence is.

@maflcko
Copy link
Member Author

maflcko commented Sep 4, 2018

I marked this up for grabs for someone to pick up and address the useful feedback by @ryanofsky

Copy link
Contributor

Choose a reason for hiding this comment

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

e here shadows the function parameter in BitcoinCore::handleRunawayException(const std::exception *e).

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 3, 2018

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

Conflicts

No conflicts as of last run.

@fanquake
Copy link
Member

fanquake commented Mar 2, 2019

Closing, leaving Up for grabs.

@fanquake fanquake closed this Mar 2, 2019
@maflcko maflcko deleted the Mf1808-qtShutdownFail branch March 2, 2019 14:39
@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