I'm using a HostedService
inside an ASP.NET core web api
that will be deployed in an IIS instance on premise (.NET Core 2.2)
. I need to ensure that the idle timeout is set to zero to ensure the background service will run continuously and I believe this can be done by setting the idle timeout on the application pool to zero. This would, however, require the IIS
administrator to perform this action upon setup so I was wondering if there is a way to configure kestrel with a zero idle timeout when its first configured in the CreateWebHostBuilder()
method of the program class.
Is this possible?
When you use IIS as a reverse proxy for an ASP.NET Core application, IIS starts the process and that idle timeout on the app pool decides when to shut down the process. IIS knows that there are no active requests, and it will just kill the process without asking the process for permission. So there is no way for your application to stop that. (You have to be aware of that if you run any background jobs in your application - IIS doesn't know about those and could kill your app in the middle of something running)
If you run without IIS, it would never automatically shut down at all, since shutting down means that nothing is listening for new connections anymore. That's the benefit of using IIS: it can restart your application if there is a catastrophic failure.
So if you plan on keeping your application behind IIS, and you want it to never shut down, then you will have to get the settings on the app pool changed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With