Skip to content

Catch all exceptions from Exit shutdown (master). #12522

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 24, 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
18 changes: 10 additions & 8 deletions src/Hosting/Hosting/src/Internal/WebHostLifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,21 @@ private void ProcessExit(object sender, EventArgs eventArgs)

private 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