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:
parent
09d3b32fe5
commit
a3300a6a60
|
|
@ -45,8 +45,14 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
{
|
{
|
||||||
AttachCtrlcSigtermShutdown(cts, done, shutdownMessage: string.Empty);
|
AttachCtrlcSigtermShutdown(cts, done, shutdownMessage: string.Empty);
|
||||||
|
|
||||||
await host.WaitForTokenShutdownAsync(cts.Token);
|
try
|
||||||
done.Set();
|
{
|
||||||
|
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...";
|
var shutdownMessage = host.Services.GetRequiredService<WebHostOptions>().SuppressStatusMessages ? string.Empty : "Application is shutting down...";
|
||||||
AttachCtrlcSigtermShutdown(cts, done, shutdownMessage: shutdownMessage);
|
AttachCtrlcSigtermShutdown(cts, done, shutdownMessage: shutdownMessage);
|
||||||
|
|
||||||
await host.RunAsync(cts.Token, "Application started. Press Ctrl+C to shut down.");
|
try
|
||||||
done.Set();
|
{
|
||||||
|
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);
|
await host.StartAsync(token);
|
||||||
|
|
||||||
var hostingEnvironment = host.Services.GetService<IHostingEnvironment>();
|
var hostingEnvironment = host.Services.GetService<IHostingEnvironment>();
|
||||||
var applicationLifetime = host.Services.GetService<IApplicationLifetime>();
|
|
||||||
var options = host.Services.GetRequiredService<WebHostOptions>();
|
var options = host.Services.GetRequiredService<WebHostOptions>();
|
||||||
|
|
||||||
if (!options.SuppressStatusMessages)
|
if (!options.SuppressStatusMessages)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue