StopApplication shuts down host but not application
See original GitHub issueDescribe the bug
When calling StopApplication() on IApplicationLifetime which is resolved from DI it only stops the host but application is kept alive and running.
To Reproduce
Using ASP.NET Core Web API template call StopApplication() on resolved interface in either controller or hosted service. Startup:
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
Stopping, where _serviceProvider
is IServiceProvider
and IApplicationLifetime
is Microsoft.Extensions.Hosting
interface.
var lifetime = _serviceProvider.GetService(typeof(IApplicationLifetime)) as IApplicationLifetime;
lifetime.StopApplication();
Expected behavior
Entire application shuts down.
Additional context
This is happening on dotnet 2.2 using WebHost to start the application.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
StopApplication shuts down host but not application #9198
When calling StopApplication() on IApplicationLifetime which is resolved from DI it only stops the host but application is kept alive and ...
Read more >Automatic Shutdown of Generic Host
A basic question for you. Host do I have the host shutdown automatically after the start code runs (not wait for Ctrl-C). Jason....
Read more >Extending the shutdown timeout setting to ensure graceful ...
The reason: HostOptions.ShutDownTimeout ... The key point here is the CancellationTokenSource that is configured to fire after HostOptions.
Read more >NET Generic Host
Inject the IHostApplicationLifetime service into any class to handle post-startup and graceful shutdown tasks. Three properties on the interface ...
Read more >Starting, stopping, and restarting Application Servers
The stop operation ends running jobs and stops the Application Server, providing a controlled shutdown. You can select options for managing ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sorry for not responding sooner, but it was a programming error on our side. Some services that were being injected weren’t disposed properly and kept the application from completely shutting down. Once we have implemented IDisposable’s on them all issues went away and it works completely as expected.
@kstreichergb It was mostly that we had some resources (long-lived connections to other services with their own lifecycles) that needed to be closed and disposed, so that all sub-processes would exit before the application itself could exit. In our case it was RabbitMQ connections that werent being closed.