Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can kestrel server in ASP.NET core be configured with idle timeout at startup

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?

like image 622
Geekn Avatar asked Sep 11 '19 16:09

Geekn


1 Answers

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.

like image 144
Gabriel Luci Avatar answered Oct 16 '22 06:10

Gabriel Luci