Doesn't shut down cleanly on Windows #20052

issue MarcoFalke opened this issue on October 1, 2020
  1. MarcoFalke commented at 11:59 AM on October 1, 2020: member

    Copied from https://bitcoin.stackexchange.com/questions/99273/why-has-bitcoin-core-stopped-shutting-down-when-windows-cleanly-shuts-down

    Every night, I do this to turn off my Windows 10 machine:

    shutdown /s

    Note that there is no "forcing flag" or anything (/f).

    Up until recently, Bitcoin Core appeared to always get the signal and cleanly shut down, just like every other application.

    However, recently, whether it was a new version of Bitcoin Core or an update to Windows 10, Bitcoin Core has stopped shutting down when it gets the signal. The reason I'm convinced of this is that, every day when I turn the machine back on, Bitcoin Core (and only that program) appears to have been uncleanly shut down/killed suddenly, as it keeps having to resync the last several days. (Perhaps just verifying the local data rather than actually downloading it.)

    I even tried keeping the Bitcoin Core GUI window open while shutting down one day, and I noticed that it didn't say the usual "Shutting down" text.

    Whether this is Bitcoin Core's fault, Windows 10's fault, or a combination, the fact remains that this happens every single time now, and it's very annoying and worrying.

    Is this issue known? Is it being worked on? What could be causing it? Would MS really change something fundamental about how applications are signaled when shutting down the OS in a minor update? (Not unthinkable.)

  2. MarcoFalke added the label Bug on Oct 1, 2020
  3. MarcoFalke added the label Windows on Oct 1, 2020
  4. hebasto commented at 10:20 AM on October 2, 2020: member

    Testing v0.20.1 and current master (60ec57b3d73e5cef71ebf3c4cdf54a4474bf492b) on Windows 10 build 19041.508.

    Can confirm, that shutdown /s interacts with bitcoin-qt in a different way than "Shut down" or "Sign out" commands from the Start menu.

  5. hebasto commented at 10:32 AM on October 2, 2020: member

    @sipsorcery

    Could shutdown /s not send WM_QUERYENDSESSION message?

  6. hebasto commented at 10:41 AM on October 2, 2020: member

    Using PowerShell Stop-Computer cmdlet fixes the issue. @MarcoFalke Is issue could be considered as solved?

  7. MarcoFalke commented at 10:54 AM on October 2, 2020: member

    Ok, but please share your findings also on the stackexchange issue

  8. MarcoFalke closed this on Oct 2, 2020

  9. hebasto commented at 11:04 AM on October 2, 2020: member

    Ok, but please share your findings also on the stackexchange issue

    It's already done by another user :)

  10. promag commented at 2:57 PM on October 2, 2020: member

    I don't think it's solved, only that there's a workaround. What's wrong with shutdown /s?

  11. MarcoFalke commented at 3:10 PM on October 2, 2020: member

    I presumed that Windows 10 broke it, so it would be an upsteam bug. But I haven't verified that.

  12. MarcoFalke reopened this on Oct 2, 2020

  13. hebasto commented at 6:57 PM on October 2, 2020: member

    I don't think it's solved, only that there's a workaround. What's wrong with shutdown /s?

    shutdown /s warns a user:

    Screenshot from 2020-10-02 21-51-28

    but it does not notify desktop apps with WM_QUERYENDSESSION message. This is not mentioned in shutdown command docs.

  14. ghost commented at 2:04 AM on October 3, 2020: none

    but it does not notify desktop apps with WM_QUERYENDSESSION message. This is not mentioned in shutdown command docs

    Looks like a Windows issue and not something wrong with bitcoin core.

  15. ghost commented at 8:36 PM on October 3, 2020: none

    I tried to reproduce the issue on my system:

    OS: Windows 10 Pro Build: 18362.1016 No updates installed after 30 August 2020

    Bitcoin Core: v 0.20.0

    Bitcoin core debug.log had this in the end for each session 2020-10-03T19:51:27Z Shutdown: done except when I had run the shutdown /s command

    Couldn't find anything interesting in eventvwr logs.

    Two interesting things that I observed:

    1. bitcoin-qt.exe launched automatically when I restarted the system after Stop-Computer PowerShell cmdlet
    2. I had chrome browser running when I ran the shutdown /s command in cmd. Couldn't find any crash logs for it after restarting. So I am assuming its only bitcoin-qt.exe that crashed with the shutdown command and no other application. Although they are completely different applications and Bitcoin Core performs few tasks before exiting which I am not aware of.

    image

    Also posted question on answers.microsoft.com however didn't get any helpful response yet:

    https://answers.microsoft.com/en-us/windows/forum/all/difference-between-shutdown-s-and-stop-computer/7239fa8e-db5b-4502-9dbd-c0c214a30a94

  16. acinis commented at 1:30 AM on October 4, 2020: none

    I have only Windows 7 box around, but it seems that when using shutdown -s WM_QUERYENDSESSION is sent but system ignores returned value, and shutdowns immediately.

    Microsoft Windows 7 Ultimate 6.1.7601 Service Pack 1 Build 7601

    Quick gist that I use to test: https://gist.github.com/acinis/23290c49c9c4bdc3a6b525aa447e79df

  17. ghost commented at 1:36 AM on October 5, 2020: none

    I tried the command shutdown /s /t 0 and it works better as explained by Harry in the accepted answer to my question.

    image

    The user had also asked a similar question on superuser which has few helpful answers and information that may help us in improving bitcoin core for Windows: https://superuser.com/questions/1590466/does-shutdown-s-really-not-send-the-close-signal-to-running-applications-i/1590739

    Interesting things:

    1. Client shutdown after receiving a WM_QUERYENDSESSION code in bitcoin core: https://github.com/bitcoin/bitcoin/blob/99813a9745fe10a58bedd7a4cb721faf14f907a4/src/qt/winshutdownmonitor.cpp#L24

    2. Best Practices for Handling Shutdown (It mentions Vista but maybe applicable for Win 10 as well): https://docs.microsoft.com/en-gb/previous-versions/windows/desktop/ms700677(v=vs.85)#best-practices-for-handling-shutdown-in-windows-vista

    3. More information related to shutdown in Windows: https://docs.microsoft.com/en-gb/windows/win32/shutdown/shutdown-changes-for-windows-vista

    4. Harry's comments on the code that manages shutdown in bitcoin core:

    I believe that if the code waited until the client shutdown was complete before responding to the WM_ENDSESSION message, then the client shutdown would be allowed to complete, provided it took no more than five seconds to do so.

    1. Link about ways for an application to shut down computer shared by acinis : https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down

    2. Generally shutdown /s does not send any "close" messages. It call one of few Win32 API functions for shutting down Windows system. These functions in turn notify aplications about shutdown/restart event via WM_QUERYENDSESSION and WM_ENDSESSION messages. Programs can then agree or try to prevent pending shutdown by responsing properly to WM_QUERYENDSESSION, eg. for stopping cleanly, etc.

    https://superuser.com/a/1590588/

  18. hebasto commented at 4:34 PM on October 5, 2020: member

    TIL :)

    C:\Users\hebasto>shutdown /?
    ...
        /t xxx     Set the time-out period before shutdown to xxx seconds.
                   The valid range is 0-315360000 (10 years), with a default of 30.
                   If the timeout period is greater than 0, the /f parameter is
                   implied.
    ...
    

    Note that "If the timeout period is greater than 0, the /f parameter is implied." is not mentioned in https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/shutdown

    So, shutdown /s is equivalent to shutdown /s /t 30 /f, i.e., it forces shutdown.

    To make things done gracefully shutdown /s /t 0 should be used.

    I've tested both shutdown /s /t 0 (to shutdown) and shutdown /l /t 0 (to log off): bitcoin-qt shutdowns nicely.

  19. MarcoFalke commented at 6:08 PM on October 5, 2020: member

    Ok, closing as upstream bug. I don't think there is anything we can do here.

  20. MarcoFalke closed this on Oct 5, 2020

  21. DrahtBot locked this on Feb 15, 2022

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-17 03:14 UTC

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