Add try..finally around RunAsync and WaitForTokenShutdownAsync #1194

The try..finally ensures that the ManualResetEventSlim which AttachCtrlcSigtermShutdown uses is set even when an exception occurs in these two methods.
This commit is contained in:
Rutger Storm 2018-05-25 18:21:26 +02:00 committed by Chris Ross
parent 09d3b32fe5
commit a3300a6a60
1 changed files with 16 additions and 5 deletions

View File

@ -45,8 +45,14 @@ namespace Microsoft.AspNetCore.Hosting
{
AttachCtrlcSigtermShutdown(cts, done, shutdownMessage: string.Empty);
await host.WaitForTokenShutdownAsync(cts.Token);
done.Set();
try
{
await host.WaitForTokenShutdownAsync(cts.Token);
}
finally
{
done.Set();
}
}
}
@ -80,8 +86,14 @@ namespace Microsoft.AspNetCore.Hosting
var shutdownMessage = host.Services.GetRequiredService<WebHostOptions>().SuppressStatusMessages ? string.Empty : "Application is shutting down...";
AttachCtrlcSigtermShutdown(cts, done, shutdownMessage: shutdownMessage);
await host.RunAsync(cts.Token, "Application started. Press Ctrl+C to shut down.");
done.Set();
try
{
await host.RunAsync(cts.Token, "Application started. Press Ctrl+C to shut down.");
}
finally
{
done.Set();
}
}
}
@ -92,7 +104,6 @@ namespace Microsoft.AspNetCore.Hosting
await host.StartAsync(token);
var hostingEnvironment = host.Services.GetService<IHostingEnvironment>();
var applicationLifetime = host.Services.GetService<IApplicationLifetime>();
var options = host.Services.GetRequiredService<WebHostOptions>();
if (!options.SuppressStatusMessages)