Recycle of App Pool kills Kestrel but does not restart
Asked Answered
C

0

8

Background

When hosting a (non-Core) ASP.net site on IIS 8+ it is possible to utilize the IIS Application Initialization Module to pro-actively initialize ('warm-up') a web application when IIS starts up (or, I believe, when an app pool is recycled). As far as I know, this is not possible when hosting a .net Core app on IIS.

I have also noticed that when hosting a .net Core (1.1) app on IIS, the dotnet.exe process (Kestrel) is killed as part of an application pool recycle event. This process is then only restarted when the first new request is made.

I'm asking the below questions because I am using Hangfire (Core) with a recurring background job and would like this job to still be executed when nobody is visiting the site for prolonged periods of time.

Questions

  1. When hosting a Core app on IIS, is there any point in using the scheduled app pool recycle functionality? The only reference I could find for this was an issue on the Github repo.

  2. If so, is it possible to automatically initialize a site or start Kestrel after a recycle of the app pool (normally this occurs every 29 hours by default).

Credent answered 27/11, 2017 at 11:15 Comment(7)
I highly recommend not running Hangfire within an IIS web application. Yes, you can do it and it kinda works. But why not just put it in a separate Windows service application, possibly using TopShelf?Roband
@Roband I appreciate your response. I may go for a scheduled task instead of a Windows service (as I have a simple use case). Hangfire was just tempting due to its ease of deployment/management and has been recommended in the past (though admittedly that article is out of date now).Credent
Yes, I've read that article and still refer some people to it. But running any sort of long running task in a web application doesn't make sense most of the time. It's eating up resources that could otherwise be used to service requests. Sure, for a small site you can get away with it. But if you need that Hangfire service to be always running, you have to configure the site to always run and I've found that to be unreliable (unless you're in Azure).Roband
@Roband Thanks. Yes it is the 'always running' part that seems problematic with IIS and Kestrel - the IIS init. module has no effect on recycle and there is no IProcessHostPreloadClient or equivalent in Core (that I know of). Given I have a 'relatively short and simple' task that needs to be run once a day, I will go with a scheduled task.Credent
Probably a good idea. You'll lose the nice dashboard functionality though....speaking of which, someone should write an open source tool that allows you to manage Windows Scheduled Tasks, similar to the Hangfire dashboard....perhaps one day when I'm bored....Roband
@CalC have you found a solution for this problem?Gravante
@SenAlexandru No, I'm afraid not. In most cases I have just resorted to setting up a continual 'ping' on the site (e.g. every 10-15min). For public facing websites this is not a easy but for internal/intranet sites, this would take the form of a scheduled task that executes a get using a PowerShell script. Not idealCredent

© 2022 - 2024 — McMap. All rights reserved.