-
Notifications
You must be signed in to change notification settings - Fork 310
Handle SIGTERMs for graceful shutdown #870
Comments
Do we want to handle both SIGTERM and SIGINT? Should they mean the same thing? Here are related issues: |
cc @glennc |
As it stands, .NET Core handles both SIGTERM and SIGINT (as well as most of the other Linux signals) in the sense that it registers for the signals. Whether it actually does something useful is up to whether the application listens on the necessary events and handles them appropriately. Given this, ASP .NET should definitely gracefully stop the application on SIGTERM because the alternative (effectively, SIGTERM equals SIGKILL) is never going to be the desired behavior. Aside from potential differences on what is output to a live console, SIGINT and SIGTERM should both stop the ASP .NET application. SIGINT works well for a dev scenario where you are locally running the process synchronously; SIGTERM is appropriate when running in the background or unattended in a server scenario. |
I can't get this to work in a simple console app on OSX: public class Program
{
public static void Main(string[] args)
{
var ended = new ManualResetEventSlim();
var starting = new ManualResetEventSlim();
AssemblyLoadContext.Default.Unloading += ctx =>
{
System.Console.WriteLine("Unloding fired");
starting.Set();
System.Console.WriteLine("Waiting for completion");
ended.Wait();
};
System.Console.WriteLine("Waiting for signals");
starting.Wait();
System.Console.WriteLine("Received signal gracefully shutting down");
Thread.Sleep(5000);
ended.Set();
}
} I tried using:
It just ends without firing any events. |
@davidfowl Does a console app catch SIGINT, though? |
Handling Console.CancelKeyPress handles SIGINT but not this. |
Bringing the bug back to 1.1 for further investigation. |
The code I got to work pulls the AssemblyLoadContext in a different way: AssemblyLoadContext.GetLoadContext(typeof(Program).GetTypeInfo().Assembly) |
I just tried your program verbatim on Debian 8.2. Worked fine there. Maybe the issue you're running into is mac specific.
|
BTW |
Then it's an OSX specific problem. We should look into this. /cc @kouvel any ideas? |
@pakrym test in yet? This one good to close? |
@muratg tests is still pending |
@pakrym please label appropriately and close ASAP. |
@stepro pointed out it should now be possible to handle SIGTERMs in addition to the SIGINTs (CTRL+C) that we already hook for graceful shutdown.
This should be especially useful for running in docker containers.
The text was updated successfully, but these errors were encountered: