question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StopApplication shuts down host but not application

See original GitHub issue

Describe 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:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Hoffscommented, Apr 19, 2019

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.

0reactions
Hoffscommented, Sep 12, 2019

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found