Skip to content

Catch all exceptions from Exit shutdown #12518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}
}