Catch all exceptions from Exit shutdown (#12518)

This commit is contained in:
Justin Kotalik 2019-07-30 12:55:13 -07:00 committed by Andrew Stanton-Nurse
parent 9feeb664da
commit c809b669b9
1 changed files with 11 additions and 8 deletions

View File

@ -134,6 +134,8 @@ namespace Microsoft.AspNetCore.Hosting
private static void AttachCtrlcSigtermShutdown(CancellationTokenSource cts, ManualResetEventSlim resetEvent, string shutdownMessage) private static void AttachCtrlcSigtermShutdown(CancellationTokenSource cts, ManualResetEventSlim resetEvent, string shutdownMessage)
{ {
void Shutdown() void Shutdown()
{
try
{ {
if (!cts.IsCancellationRequested) if (!cts.IsCancellationRequested)
{ {
@ -141,12 +143,13 @@ namespace Microsoft.AspNetCore.Hosting
{ {
Console.WriteLine(shutdownMessage); Console.WriteLine(shutdownMessage);
} }
try
{
cts.Cancel(); cts.Cancel();
} }
catch (ObjectDisposedException) { }
} }
// When hosting with IIS in-process, we detach the Console handle on main thread exit.
// Console.WriteLine may throw here as we are logging to console on ProcessExit.
// We catch and ignore all exceptions here. Do not log to Console in thie exception handler.
catch (Exception) { }
// Wait on the given reset event // Wait on the given reset event
resetEvent.Wait(); resetEvent.Wait();