Replies: 1 comment
-
|
Hey, so when ASP.NET Core doesn't exit immediately after Ctrl+C, it usually means something in your app is preventing the Host from completing its graceful shutdown. By default, ASP.NET Core gives services 5 seconds (configurable) to clean up before it forces the process to end, which is the timeout you’re seeing. To find the culprit, here are the most common causes and how to investigate them: 1. Background services not stoppingAnything that implements:
What to check: public override async Task StopAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("Stopping MyService...");
await base.StopAsync(stoppingToken);
}2. Long-running tasks without cancellationIf you started tasks manually using What to check: 3. Open connections or serversCommon blockers:
What to check: In appsettings.json: {
"Logging": {
"LogLevel": {
"Microsoft.Hosting.Lifetime": "Debug"
}
}
}Then rerun the app and hit Ctrl+C; the logs will tell you which hosted service hasn’t stopped. 4. Use "dump" and tools if neededIf you still can’t find it, generate a process dump while it’s stuck and inspect it: Windows Linux Look for:
5. Increase shutdown loggingYou can also hook into host events: builder.Services.Configure<HostOptions>(options =>
{
options.ShutdownTimeout = TimeSpan.FromSeconds(30);
});This gives more time for logging and reveals what’s not finishing in time. Basically, something in your app isn't respecting cancellation or not finishing during Hope this helps. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an aspnetcore application. When I switch to Production then after pressing Ctrl+C I see in the console
Application is shutting down...but after that process is still active - exits after a timeout.How can I find what is cause of that? Which part of my code is holding my application from gracefully exit?
Beta Was this translation helpful? Give feedback.
All reactions