Skip to content

Commit

Permalink
Catch all exceptions from Exit shutdown (#12518)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotalik authored and analogrelay committed Jul 30, 2019
1 parent 9feeb66 commit c809b66
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/Hosting/Hosting/src/WebHostExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,21 @@ private static void AttachCtrlcSigtermShutdown(CancellationTokenSource cts, Manu
{
void Shutdown()
{
if (!cts.IsCancellationRequested)
try
{
if (!string.IsNullOrEmpty(shutdownMessage))
{
Console.WriteLine(shutdownMessage);
}
try
if (!cts.IsCancellationRequested)
{
if (!string.IsNullOrEmpty(shutdownMessage))
{
Console.WriteLine(shutdownMessage);
}
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
resetEvent.Wait();
Expand Down Expand Up @@ -184,4 +187,4 @@ private static async Task WaitForTokenShutdownAsync(this IWebHost host, Cancella
await host.StopAsync();
}
}
}
}

0 comments on commit c809b66

Please sign in to comment.