GUI: allow a clean Bitcoin-Qt shutdown #1417

pull Diapolo wants to merge 1 commits into bitcoin:master from Diapolo:hideTrayIcon changing 2 files +7 −1
  1. Diapolo commented at 8:50 PM on June 4, 2012: none

    When using Bitcoin-Qt don't call exit() in Shutdown(), to allow a clean exit for Bitcoin-Qt - this ensures the removal of the tray-icon (in BitcoinGUI destructor) after the core is shutdown.

    On Windows the tray-icon was still visible after a shutdown, which could lead to many orphan icons in the tray that only disappeared after hovering them with the mouse. This is now fixed.

  2. luke-jr commented at 10:10 PM on June 8, 2012: member

    Does this wait until the client is actually shutdown?

  3. Diapolo commented at 10:32 PM on June 8, 2012: none

    @luke-jr The function is called, after we hide the main Window in preparation of a shutdown, which is the right place.

  4. luke-jr commented at 10:40 PM on June 8, 2012: member

    No, the current behaviour showing the icon until the client has exited completely is by design. See bug #908

  5. Diapolo commented at 10:46 PM on June 8, 2012: none

    Alright, then the call is miss-placed, but it IS needed to fix the icon still shown after shutdown issue. Will update to find a better place :), thanks for pointing that out.

  6. Diapolo commented at 11:45 PM on June 8, 2012: none

    @luke-jr Okay, I took a look and come to the conclusion as it's not possible to pretend, when trayIcon will be deleted, we have to call trayIcon->hide() as long as we know it is controllable.

    In the present code from master branch this will not succeed and so the icon is displayed, even if the app is closed already. Which one is worse, a tray-icon when there is no app or a missing tray-icon, while shutting down the app?

    Edit: I think it's overkill to re-implement the class destructor from QSystemTrayIcon to call hide there.

  7. luke-jr commented at 11:50 PM on June 8, 2012: member

    Why can't you simply grab the pointer and hold onto it until shutdown completes?

  8. Diapolo commented at 12:03 AM on June 9, 2012: none

    Seems possible, but I'm not sure if I can do this in a clean and sufficient way. I'm sure other devs would say don't touch the Shutdown() function for hiding a system tray-icon and I think so too. If you have an easy and working solution for both problems here, you're welcome ;).

  9. luke-jr commented at 12:28 AM on June 9, 2012: member
                 Shutdown(NULL);
    +            window.hideTrayIcon();
    
  10. Diapolo commented at 12:33 AM on June 9, 2012: none

    Well Shutdown(NULL) calls exit(), so it won't return and cannot reach window.hideTrayIcon();

  11. Diapolo commented at 1:47 PM on June 9, 2012: none

    @laanwj Any idea for this one ;)?

  12. laanwj commented at 7:28 AM on June 10, 2012: member

    Yeah, good catch. Shutdown calls exit()... that kind of sucks. This means that execution flow never leaves the function, and thus the destructor is never called.

    Luke-jr is right, though, that hiding the icon before the shutdown function also isn't desired behavior.

    The reason that Shutdown calls exit is that, with bitcoind, any thread can call Shutdown(). No matter what thread calls it, it has to make sure that the process exits. With the UI, the UI thread is the only thread allowed to actually shutdown the core. Hence uiinterface->QueueShutdown().

    As with the UI we have control over what happens after Shutdown, this means that you could #ifdef the final exit() from Shutdown to not be called when QT_GUI. This will fix the problem without needing any of the changes in this pull.

  13. Diapolo commented at 11:24 AM on June 10, 2012: none

    @laanwj Sounds good, will test and update this pull to only do that change.

  14. Diapolo commented at 11:46 AM on June 10, 2012: none

    Updated and verified to work (on Windows). Tray icon is removed, but is visible until core is shutdown.

  15. laanwj commented at 2:20 PM on June 10, 2012: member

    ACK

  16. TheBlueMatt commented at 8:18 PM on June 10, 2012: member

    NACK, bitcoin-qt never exits if you send it SIGTERM after this (though, to be fair, its not really any worse to how it used to SEGFAULT every once in a while, in any case, maybe we could fix that too)

  17. Diapolo commented at 8:28 PM on June 10, 2012: none

    SIGTERM is non Windows stuff, I need your help here :D.

    When receiving that signal it is handled via HandleSIGTERM(), which simply sets fRequestShutdown to true. I could only find ThreadMessageHandler2(), which seems to initiate a Shutdown(), right?

  18. TheBlueMatt commented at 8:31 PM on June 10, 2012: member

    Correct, after SIGTERM, we end up just calling Shutdown. I suppose we really just need to replace our Shutdown calls with uiInterface.QueueShutdown() (have I mentioned how ugly that looks when we are building without GUI?).

  19. Diapolo commented at 8:40 PM on June 10, 2012: none

    Wouldn't it work if I just extend my pull to modify Shutdown() to be like this in the end:

    <pre> // ensure a clean exit for Bitcoin-Qt #ifndef QT_GUI printf("Bitcoin exited\n\n"); exit(0); #else uiInterface.QueueShutdown(); #endif </pre>

  20. laanwj commented at 8:42 PM on June 10, 2012: member

    Sounds like a good solution. That would also likely fix the current crashes when sending sigterm to the ui executable.

  21. laanwj commented at 8:45 PM on June 10, 2012: member

    Last comment was @bluematt.

    Do not call queueshutdown from Shutdown that will cause big trouble! The qt event loop is long dead by that point and for non-ui you'd be calling shutdown recursively.

  22. Diapolo commented at 8:46 PM on June 10, 2012: none

    I will update, but I need one of you (if you use Linux / Unix) to test and verify this.

  23. TheBlueMatt commented at 8:47 PM on June 10, 2012: member

    Personally, Id like to not have to see uiInterface.QueueShutdown everywhere, but be able to call Shutdown which calls uiInterface.QueueShutdown which can call FinishShutdown in its callback, or simply have Shutdown call FinishShutdown directly if we dont have GUI...but maybe Im the only one who doesnt like having to uiInterface in bitcoind...

  24. when using Bitcoin-Qt don't call exit() in Shutdown(), but uiInterface.QueueShutdown(), to allow a clean exit for Bitcoin-Qt (even via SIGTERM) - this ensures the removal of the tray-icon (in BitcoinGUI destructor) after the core is shutdown c742f60933
  25. Diapolo commented at 8:49 PM on June 10, 2012: none

    @laanwj Damn, I was too quick ... and missunderstood your comment :-/.

  26. Diapolo commented at 9:09 PM on June 10, 2012: none

    @laanwj Well no, I don't get it ... calling uiInterface.QueueShutdown(); triggers QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);, which puts a quit() command in the main event loop, right? So why should the event loop be gone when we are in Shutdown()? I can't find the connection between the two.

  27. Diapolo commented at 9:39 PM on June 10, 2012: none

    @laanwj Don't bother with my last question, I had a discussion on IRC with BlueMatt and will come up with a new pull-request tomorrow and close this one.

  28. Diapolo closed this on Jun 10, 2012

  29. laanwj commented at 5:27 AM on June 11, 2012: member

    There is nothing wrong with the current sequence. QueueShutdown first winds down the Qt event loop, which, returning in the main function, properly calls Shutdown.

    You cannot simply spawn Shutdown in a new thread when the UI is running, this results in crashes so it takes a safer way.

    I really don't care about "seeing ui.QueueShutdown" everywhere. That's confounding bikeshedding with a real issue. Sure, if you can come up with a more proper name in non-ui context that's great but don't try to fix what's not broken!!!

  30. Diapolo commented at 5:53 AM on June 11, 2012: none

    See #1439, which I think is rather elegant.

  31. suprnurd referenced this in commit e6543b9c7c on Dec 5, 2017
  32. lateminer referenced this in commit e59a724d2d on Jan 22, 2019
  33. lateminer referenced this in commit 592aa52fca on May 6, 2020
  34. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-21 18:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me