[release/5.0] Handle windows shutdown event #41182
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #41101 to release/5.0
/cc @sbomer
Customer Impact
This fixes #36089, which has a fair amount of interest and is also a partner ask.
Testing
Automated testing is challenging since I don't see a documented way to trigger these events (other than triggering a shutdown or running in a container). I tested this locally to confirm that it produces the desired behavior on 'docker stop', and also for windows shutdown of service processes. I have tested with a simple console app that hooks into
ProcessExit
, an app that uses ConsoleLifetime with the ASP.NET generic host, and an app that uses a custom lifetime which behaves similarly to ConsoleLifetime.Risk
Low risk - it seems unlikely to me that apps would be broken by having cleanup code in
ProcessExit
run during shutdown when it didn't used to. The change is also very scoped and doesn't change the behavior of existing events like Ctrl+C, Ctrl+Break, and a windows close event.@jeffschwMSFT @agocke