aspnetcore: SIGTERM signal in .NET 6 app deployed in azure Kubernetes service is not triggered
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
1
I have a .NET 6 application. This application contains a BackgroundService that is used to handler background jobs. These jobs are fired on a certain time based on different schedules.
I need to implement graceful shutdown when the application is stopping, because there might be some running jobs and I want to complete the jobs before stopping the application.
The app is deployed in Azure Kubernetes Service, when running this command kubectl delete pod {podname} to delete a certain pod, I am not able to handle the sigterm and write my logic to handle graceful shutdown.
I am using the IHostApplicationLifetime and registering on the ApplicationStopping event.
IHostApplicationLifetime _applicationLifetime; _applicationLifetime.ApplicationStopping.Register(OnAppStopping);
In the docker file I added the below line
STOPSIGNAL SIGTERM
The OnAppStopping is never fired on AKS.
Expected Behavior
The ApplicationStopping event should be triggered in order to handle graceful stop of the application
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
6
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 26 (18 by maintainers)
I used a minimal k8s config - please let me know if you’re doing something different.
And from AKS
(The color markers appear to have been cleaned up in .net core 7)
Due to the way VS runs docker containers, your app will never get SIGTERM if the container is run from VS (even if you’re not debugging). I understand this is part of optimizing the inner dev loop to not require restarting the container every launch.
However, if you run the container another way, e.g. by right clicking on the dockerfile and selecting “Build docker image” and then running the resulting image (e.g. in Docker Desktop), you should see logger and/or console output when you send SIGTERM to the container.
Sorry this is such a gotcha - I spent a while scratching my head over it myself.
We’re all on vacation. Expect updates in a couple of weeks.
same here, any update on this?
This is the sort of information we need to reproduce the issue (see the “steps to reproduce” part of the issue above).
This isn’t a k8s manifest, but it seems like you can reproduce the issue on with docker kill so that will be the repro.
I have 2 more questions: