Consume PosixSignal in Hosting's ConsoleLifetime (#56057)
authorEric Erhardt <eric.erhardt@microsoft.com>
Thu, 22 Jul 2021 04:20:48 +0000 (23:20 -0500)
committerGitHub <noreply@github.com>
Thu, 22 Jul 2021 04:20:48 +0000 (23:20 -0500)
commit36f3f9787eada1eb891b16a1e79a9dde2bcc6db4
treea211d495c6fda93e7fac3de932f3a90ce8fecc02
parente60882e13769df03efe6c564311b9d3793e693d6
Consume PosixSignal in Hosting's ConsoleLifetime (#56057)

* Add NetCoreAppCurrent target to Microsoft.Extensions.Hosting

* Handle SIGTERM in Hosting and handle just like SIGINT (CTRL+C)

Don't listen to ProcessExit on net6.0+ in Hosting anymore. This allows for Environment.Exit to not hang the app.
Don't clobber ExitCode during ProcessExit now that SIGTERM is handled separately.

For non-net6.0 targets, only wait for the shutdown timeout, so the process doesn't hang forever.

Fix #55417
Fix #44086
Fix #50397
Fix #42224
Fix #35990

* Remove _shutdownBlock on netcoreappcurrent, as this is no longer waited on
* Change Console.CancelKeyPress to use PosixSignalRegistration SIGINT and SIGQUIT
* Use a no-op lifetime on mobile platforms

* Add docs for shutdown
16 files changed:
src/libraries/Microsoft.Extensions.Hosting.Systemd/tests/UseSystemdTests.cs
src/libraries/Microsoft.Extensions.Hosting/Directory.Build.props
src/libraries/Microsoft.Extensions.Hosting/docs/HostShutdown.md [new file with mode: 0644]
src/libraries/Microsoft.Extensions.Hosting/docs/images/HostShutdownSequence.png [new file with mode: 0644]
src/libraries/Microsoft.Extensions.Hosting/ref/Microsoft.Extensions.Hosting.cs
src/libraries/Microsoft.Extensions.Hosting/src/HostBuilder.cs
src/libraries/Microsoft.Extensions.Hosting/src/HostBuilder.netcoreapp.cs [new file with mode: 0644]
src/libraries/Microsoft.Extensions.Hosting/src/HostBuilder.notnetcoreapp.cs [new file with mode: 0644]
src/libraries/Microsoft.Extensions.Hosting/src/HostingHostBuilderExtensions.cs
src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs
src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.netcoreapp.cs [new file with mode: 0644]
src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.notnetcoreapp.cs [new file with mode: 0644]
src/libraries/Microsoft.Extensions.Hosting/src/Internal/NullLifetime.cs [new file with mode: 0644]
src/libraries/Microsoft.Extensions.Hosting/src/Microsoft.Extensions.Hosting.csproj
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/ConsoleLifetimeExitTests.cs [new file with mode: 0644]
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Microsoft.Extensions.Hosting.Unit.Tests.csproj