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

1

6

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?

Subdominant answered 11/9, 2019 at 16:15 Comment(5)
Do you mean that you will host with only Kestrel and take IIS out of the equation?Rubber
By idle timeout, do you mean how long an open connection will wait for the client?Menticide
@Nate By idle timeout, I'm referring to the period of time where no inactivity occurs (no API calls) and the process shuts down to save system resources.Subdominant
@Gabriel - When I use the CreateDefaultBuilder, that calls Kestrel behind the scenes correct? Then I would deploy that application to an IIS host. So if the setting is in the IIS host, you are probably going to say it has nothing to do with kestel huh?Subdominant
I'm not saying Kestrel doesn't have the option, but IIS is going to take precedence. IIS is what starts and stops the process.Rubber
R
5

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.

Rubber answered 11/9, 2019 at 17:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.