parent
37a48d897b
commit
0456c9dcc9
|
|
@ -13,6 +13,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal
|
||||||
private readonly string _shutdownMessage;
|
private readonly string _shutdownMessage;
|
||||||
|
|
||||||
private bool _disposed = false;
|
private bool _disposed = false;
|
||||||
|
private bool _exitedGracefully = false;
|
||||||
|
|
||||||
public WebHostLifetime(CancellationTokenSource cts, ManualResetEventSlim resetEvent, string shutdownMessage)
|
public WebHostLifetime(CancellationTokenSource cts, ManualResetEventSlim resetEvent, string shutdownMessage)
|
||||||
{
|
{
|
||||||
|
|
@ -24,6 +25,11 @@ namespace Microsoft.AspNetCore.Hosting.Internal
|
||||||
Console.CancelKeyPress += CancelKeyPress;
|
Console.CancelKeyPress += CancelKeyPress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void SetExitedGracefully()
|
||||||
|
{
|
||||||
|
_exitedGracefully = true;
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (_disposed)
|
if (_disposed)
|
||||||
|
|
@ -46,6 +52,12 @@ namespace Microsoft.AspNetCore.Hosting.Internal
|
||||||
private void ProcessExit(object sender, EventArgs eventArgs)
|
private void ProcessExit(object sender, EventArgs eventArgs)
|
||||||
{
|
{
|
||||||
Shutdown();
|
Shutdown();
|
||||||
|
if (_exitedGracefully)
|
||||||
|
{
|
||||||
|
// On Linux if the shutdown is triggered by SIGTERM then that's signaled with the 143 exit code.
|
||||||
|
// Suppress that since we shut down gracefully. https://github.com/aspnet/AspNetCore/issues/6526
|
||||||
|
Environment.ExitCode = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Shutdown()
|
private void Shutdown()
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await host.WaitForTokenShutdownAsync(cts.Token);
|
await host.WaitForTokenShutdownAsync(cts.Token);
|
||||||
|
lifetime.SetExitedGracefully();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
@ -91,6 +92,7 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await host.RunAsync(cts.Token, "Application started. Press Ctrl+C to shut down.");
|
await host.RunAsync(cts.Token, "Application started. Press Ctrl+C to shut down.");
|
||||||
|
lifetime.SetExitedGracefully();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
|
||||||
[ConditionalFact]
|
[ConditionalFact]
|
||||||
[OSSkipCondition(OperatingSystems.Windows)]
|
[OSSkipCondition(OperatingSystems.Windows)]
|
||||||
[OSSkipCondition(OperatingSystems.MacOSX)]
|
[OSSkipCondition(OperatingSystems.MacOSX)]
|
||||||
[OSSkipCondition(OperatingSystems.Linux)] // https://github.com/aspnet/AspNetCore-Internal/issues/1687
|
|
||||||
public async Task ShutdownTestRun()
|
public async Task ShutdownTestRun()
|
||||||
{
|
{
|
||||||
await ExecuteShutdownTest(nameof(ShutdownTestRun), "Run");
|
await ExecuteShutdownTest(nameof(ShutdownTestRun), "Run");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue