Skip to content

Graceful termination on shutdown, logoff, and service stop#647

Merged
ReenigneArcher merged 3 commits intoLizardByte:nightlyfrom
cgutman:graceful_shutdown
Dec 29, 2022
Merged

Graceful termination on shutdown, logoff, and service stop#647
ReenigneArcher merged 3 commits intoLizardByte:nightlyfrom
cgutman:graceful_shutdown

Conversation

@cgutman
Copy link
Collaborator

@cgutman cgutman commented Dec 28, 2022

Description

This PR addresses several issues handling service stop, shutdown, and logoff on Windows:

  • Moves Sunshine further back in the priority of processes to be terminated to keep connectivity as long as possible during logoff. This allows interaction with the screen that appears when apps are blocking shutdown.
  • Adds handling for WM_ENDSESSION to allow Sunshine to gracefully close itself when the user session is ending. Unfortunately, we have to use the hidden window solution rather than the simpler SetConsoleCtrlHandler() API because the display capture APIs we use cause gdi32.dll to be loaded.
  • Sends a Ctrl-C to gracefully terminate Sunshine when SunshineSvc is stopped or the system is shutting down. This requires a helper process because we can't attach to Sunshine's console from the service since it's in a different session.
  • Fixes a breakage introduced by Spawn Sunshine.exe in a job object, so it is terminated if SunshineSvc.exe dies #602 that prevented Sunshine from spawning again after a logout+login cycle

Screenshot

Issues Fixed or Closed

Fixes Sunshine not reverting back to the default audio output after logoff, shutdown, or service stop while streaming

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update (updates to dependencies)
  • Documentation update (changes to documentation)
  • Repository update (changes to repository files, e.g. .github/...)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the in code docstring/documentation-blocks for new or existing methods/components

Branch Updates

LizardByte requires that branches be up-to-date before merging. This means that after any PR is merged, this branch
must be updated before it can be merged. You must also
Allow edits from maintainers.

  • I want maintainers to keep my branch updated

@cgutman cgutman force-pushed the graceful_shutdown branch 2 times, most recently from 3a0aa54 to 188e358 Compare December 29, 2022 04:29
@cgutman
Copy link
Collaborator Author

cgutman commented Dec 29, 2022

I ended up finding and fixing some additional bugs after doing some testing in another branch that is fixing/removing std::abort() calls. They were hidden before because Sunshine would always crash on "graceful" shutdown due to hitting the std::abort() in publish.cpp.

@KuleRucket
Copy link
Contributor

It would be great if the "Press enter to continue" was disabled for Linux all together. You would not normally need to hold a terminal window open in Linux so this has always been mildly irritating.

@ReenigneArcher
Copy link
Member

It would be great if the "Press enter to continue" was disabled for Linux all together. You would not normally need to hold a terminal window open in Linux so this has always been mildly irritating.

Same for Windows to be honest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants