You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AssemblyLoadContext.Unloading is not called when TERM signal sent to application #6733
Based on #2688 and #5205, I would expect the default AssemblyLoadContext's Unloading event to fire when the application receives a SIGTERM. However, the event handler doesn't seem to ever be called.
Code to reproduce:
public class Program
{
private static void unloadTask(AssemblyLoadContext obj)
{
Console.WriteLine("Unloading");
}
public static void Main(string[] args)
{
Console.WriteLine("Starting App");
AssemblyLoadContext.Default.Unloading += unloadTask;
try
{
Console.ReadLine();
}
catch (System.Exception)
{
Console.WriteLine("aborted?");
}
}
}
$dotnet run
$kill -TERM pid
output:
Starting App
expected output:
Starting App
Unloading
Same behavior with dotnet 1.0.1 on OSX and Windows 10
I haven't been able to get this event to fire either. It is possible on Linux though, but only if you run the process in the background and then kill it using "kill <pid>". If you run it and then press CTRL-C, it won't fire either.
Our expectation was that SIGTERM should raise the Unloading event, so this sounds like a bug. I'm not sure about Ctrl+C / SIGINT, it also seems like a graceful shutdown case so I guess it should also raise the event. I'll take a look at both of these.
I would prefer that a SIGINT NOT call Unloading event handler because I would like the two signals (SIGINT and SIGTERM) be distinguishable. SIGINT currently fires the Console.CancelKeyPress, and because the SIGINT is only applicable in a foreground/console application, this behavior seems sufficient.
If I wanted to take different actions on each event, I could choose to do that by having different event handling code for each event. The Unloading event would give me a way to handle SIGTERM and the Console.CancelKeyPress would give me a way to handle SIGINT. If I wanted to take the same action on both events, I could choose to execute common code from each handler.
Pressing CTRL + C once from docker-compose didn't fire either Console.CancelKeyPress or AssemblyLoadContext.Unloading for me. I will double check.
Also, is there any timeouts defined for these hooks?
Tugberk
Sent from my iPhone - excuse the terseness and typos
On 12 Dec 2016, at 23:33, Doug Powers <[email protected]<mailto:[email protected]>> wrote:
SIGINT currently fires the Console.CancelKeyPress
It looks like SIGTERM is raising the Unloading event on Linux but not on OSX, this is a bug.
SIGINT is raising the Unloading event on both, but CoreFX only starts listening for the signal when a callback is registered with the CancelKeyPress event, so if nothing is registered, the Unloading event is not raised and the app terminates. It should be raising the Unloading event in any case, something wrong here too. Should handle SIGQUIT in the same manner as well.
@kouvel - can you check the Windows behavior w.r.t. the SIGINT / SIGQUIT handling and the Unloading event? It would be good to keep both Windows and Unix on the same plan.
On Windows, when a handler is registered for CancelKeyPress, Ctrl+C & Ctrl+Break both raise the Unloading event (treated as graceful shutdown). When no handler is registered, the Unloading event is not raised (treated as abrupt shutdown). Should we be consistent and treat them both as either graceful or abrupt shutdown? I feel that registering for CancelKeyPress shouldn't change the shutdown behavior.
Activity
tugberkugurlu commentedon Dec 11, 2016
Same here: https://github.com/dotnet/coreclr/issues/2688#issuecomment-266290169
m-jepson commentedon Dec 11, 2016
I haven't been able to get this event to fire either. It is possible on Linux though, but only if you run the process in the background and then kill it using "kill <pid>". If you run it and then press CTRL-C, it won't fire either.
janvorli commentedon Dec 12, 2016
@kouvel, @adityamandaleeka, @stephentoub - it seems that the intent of #4950, https://github.com/dotnet/corefx/issues/5205 and dotnet/coreclr#4309 was to enable an app to hook to an event that gets invoked when the app receives the SIGTERM, but it doesn't seem to work. I had hard time figuring out from the lengthy discussions in those issues / PRs where we have finally landed. Does one of you know if the current behavior is a bug or if we have just not finished the work as expected?
kouvel commentedon Dec 12, 2016
Our expectation was that SIGTERM should raise the Unloading event, so this sounds like a bug. I'm not sure about Ctrl+C / SIGINT, it also seems like a graceful shutdown case so I guess it should also raise the event. I'll take a look at both of these.
janvorli commentedon Dec 12, 2016
As for the SIGINT, it is handled in corefx in pal_console.cpp. It is supposed to call a callback registered using SystemNative_RegisterForCtrl.
dougkpowers commentedon Dec 12, 2016
I would prefer that a SIGINT NOT call Unloading event handler because I would like the two signals (SIGINT and SIGTERM) be distinguishable. SIGINT currently fires the Console.CancelKeyPress, and because the SIGINT is only applicable in a foreground/console application, this behavior seems sufficient.
If I wanted to take different actions on each event, I could choose to do that by having different event handling code for each event. The Unloading event would give me a way to handle SIGTERM and the Console.CancelKeyPress would give me a way to handle SIGINT. If I wanted to take the same action on both events, I could choose to execute common code from each handler.
janvorli commentedon Dec 12, 2016
@dougkpowers I also believe that's the expected behavior.
tugberkugurlu commentedon Dec 13, 2016
kouvel commentedon Dec 13, 2016
It looks like SIGTERM is raising the Unloading event on Linux but not on OSX, this is a bug.
SIGINT is raising the Unloading event on both, but CoreFX only starts listening for the signal when a callback is registered with the CancelKeyPress event, so if nothing is registered, the Unloading event is not raised and the app terminates. It should be raising the Unloading event in any case, something wrong here too. Should handle SIGQUIT in the same manner as well.
kouvel commentedon Dec 13, 2016
AppDomain.DomainUnloading, which was added recently for ns2.0, is not raised at all, issue dotnet/coreclr#8622
janvorli commentedon Dec 13, 2016
@kouvel - can you check the Windows behavior w.r.t. the SIGINT / SIGQUIT handling and the Unloading event? It would be good to keep both Windows and Unix on the same plan.
kouvel commentedon Dec 13, 2016
On Windows, when a handler is registered for CancelKeyPress, Ctrl+C & Ctrl+Break both raise the Unloading event (treated as graceful shutdown). When no handler is registered, the Unloading event is not raised (treated as abrupt shutdown). Should we be consistent and treat them both as either graceful or abrupt shutdown? I feel that registering for CancelKeyPress shouldn't change the shutdown behavior.
kouvel commentedon Dec 13, 2016
In .NET desktop:
Maybe we should map the Core behavior to the desktop behavior for SIGINT and SIGQUIT. Could be considered a breaking change though. Thoughts?
SIGTERM should still be treated as graceful shutdown and raise the appropriate events.
kouvel commentedon Dec 13, 2016
CC @gkhanna79
Handle SIGTERM on OSX (#10723)