Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling SIGTERM in asp.net core middleware in docker container #11391

Closed
meanin opened this issue Nov 2, 2018 · 7 comments
Closed

Handling SIGTERM in asp.net core middleware in docker container #11391

meanin opened this issue Nov 2, 2018 · 7 comments

Comments

@meanin
Copy link

meanin commented Nov 2, 2018

Hi All,
is it possible at all? I created simple asp.net core application here. The application is running in linux docker container. Now, I am trying to implement graceful shutdown, with waiting for current request completion. I tried many different ways, starts from AppDomain.CurrentDomain.ProcessExit += OnProcessExit, going trough Console.CancelKeyPress += ConsoleOnCancelKeyPress and finished on AssemblyLoadContext.Default.Unloading += OnUnloading. I tried to place it inside a middleware as well as on top of program.cs. I am stoping docker with command below:
docker stop -t 30 containerId
Docker documentation says, that this should cause SIGTERM on a first try, wait given time and raise SIGKILL.

I already saw issues:
aspnet/Hosting#870
https:/aspnet/Hosting/issues/1527
https:/dotnet/coreclr/issues/2688
https:/dotnet/coreclr/issues/8565

Any guess?

@davidfowl
Copy link
Member

Graceful shutdown already works out of the box with ASP.NET Core so there’s no need to re-implement it.

@meanin
Copy link
Author

meanin commented Nov 2, 2018

Is this the reason, why I cannot get any of these events while debbuging?

@davidfowl
Copy link
Member

Maybe? I’m not sure about that but I know you can delete your code because it’s handled

@meanin
Copy link
Author

meanin commented Nov 7, 2018

Hi again,
Thank you for your interest in my issue. I will skip graceful handling right now, but I want to understand, how to handle sigterm in my app.

I've created a simple demo here, which is not working, unfortunately. I am going to work on that further in some free time and update this thread :)
Regards

@meanin
Copy link
Author

meanin commented Nov 9, 2018

Tested in a 2 .net core application:

  1. generic host here
  2. generic host alongside with asp.net application here

In both cases, I wasn't able to catch this while debugging, while running container in interactive mode shows log messages on all events.

The last thing that I want to test is IApplicationLifetime on docker container interactive. I suspect that it will be working, but again, I won't be able to debug.

Regards

@meanin
Copy link
Author

meanin commented Nov 9, 2018

I can confirm that all of the solutions are working on docker run -it mode. Issue closed.

@meanin meanin closed this as completed Nov 9, 2018
@davidfowl
Copy link
Member

@meanin great!

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants