Closed RoySalisbury closed 5 years ago
@RoySalisbury Does the app this issue on other platforms? Like a non pi linux?
Could you share an app that reproduces this?
I can try to create a small test case for you, but it appears it is not a framework/platform issue as much as a local app issue.
Basically, if one of the IHostedService apps does not start up correctly, then the main ASP.NET host does not complete its startup fully. The web site runs, but the Ctrl-C handler of the main host does not get hooked up.
Once I corrected the startup of the errant IHostedService, and the main ASP.NET host was able to fully start, everything worked.
So, bug? Sorta .. but if your code is correct, it does not happen. If you want to look into it as a edge case I can try to get something to you, but for me, its no longer an issue.
@RoySalisbury OK thanks for the explanation. If more folks start hitting this, we'll consider investigating this further, but for now I think it's fine, especially since you're unblocked.
Note the IHostedService exception handling behavior is different for the new generic host. I.e. there isn't any, if your IHostedService.StartAsync throws then you'll see that exception surface in Main.
We reproduced this issue.
When we run app from console, it stopping correctly. But when app is running as daemon via systemd it still running after command sudo systemctl stop %my_app_name%
. As we investigated, default kill signal is SIGTERM. If we change it manual in config, all works fine (example of config listed below):
[Unit]
Description=AMI Proxy service (dotnet)
[Service]
ExecStart=/usr/bin/dotnet /opt/amiproxy/SIISLtd.DEX.AmiProxy.dll
WorkingDirectory=/opt/amiproxy/
User=maxim
Restart=on-failure
SyslogIdentifier=amiproxy
PrivateTmp=true
KillSignal=SIGTERM
[Install]
WantedBy=multi-user.target
Sample app All information about our environment: dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.1.403
Commit: 04e15494b6
Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64
Base Path: /usr/share/dotnet/sdk/2.1.403/
Host (useful for support):
Version: 2.1.5
Commit: 290303f510
.NET Core SDKs installed:
2.1.403 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
OS:
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
This example from docs is not stopped by CTRL+C
:
public static async Task Main(string[] args)
{
var host = new HostBuilder()
.Build();
await host.RunAsync();
}
@Tratcher is the SIGTERM issue @Markeli posted resolved by https://github.com/aspnet/AspNetCore/pull/8294 ?
@voroninp I can't reproduce that issue, it terminated just fine for me. Could you describe the specific environment you're running in? For example: What OS are you running? Are you running in systemd
? Etc.
Unclear, I hadn't reproduced it yet either. #8294 should have only changed the exit code, not affected if it did or did not exit.
Ok, so we do still need to investigate if SIGTERM is working in this scenario then.
Tested this sample (https://github.com/aspnet/AspNetCore/issues/5940#issuecomment-449364978) on 2.2.4 (2.2.203) on Ubuntu 18.04 and CTL+C is working on the console as expected.
Backlogging any investigation of daemons until we focus on those in a future milestone.
Ok, closing this for now then. @voroninp if you have more information about the environment you are in where Ctrl-C is not working, please let us know!
I have 2 hosted services running within my ASPNET Core application.
Prior to 2.1.4 (2.1.402) a CTRL-C would cause the cancellationToken in each of the hostedservices to be set so that I could exist the tasks and the process would stop. However, that is no longer the case.
The CancellationToken does not get set and the hosted services DO NOT stop. Which will not let the ASPNET main task stop either. I get the message in the console "Application is shutting down", but nothing happens.
This is running on the latest Raspbian image on a Pi 3 B+.
Anyone else having this issue?