3

I need to keep my blazor server side app alive all time.

I tried to set my iis 8.5 start mode setting to alwaysrunning and idle to 0 but still shutting down the app and caught stopping signal... after between 23h to 29h...

enter image description here

what i have to do to keep it alive, which setting i missed? Do i have to add code on web.config?

Khalid Ab
  • 195
  • 1
  • 3
  • 17
  • Hosting in IIS means that you will get the IIS app pool recycles which means that your application restarts. You will need to configure IIS for this, or avoid hosting your app in IIS if you truly want your application to never restart. – poke Mar 02 '21 at 16:50
  • Why do you want your app to never stop? What problem are you trying to solve by doing so? – mason Mar 02 '21 at 17:58
  • 1
    This article shows how to disable the 29hour process recycling: https://serverfault.com/questions/333907/what-should-i-do-to-make-sure-that-iis-does-not-recycle-my-application – Jason D Mar 02 '21 at 19:10
  • because i use hangfire sheduling task to do every sunday @mason – Khalid Ab Mar 02 '21 at 20:56
  • @JasonD it seam that is an old version of iis ... in my case its for an blazor server side webapp .net core 3.1 hosting in iis 8.5 but i will try if i find this setting on it ... neverknows – Khalid Ab Mar 02 '21 at 20:59
  • Hangfire is great - but keep in mind that coupling it into a web application isn't the most durable solution. You can host Hangfire's background job server in a console app/Windows service, and those are designed to run constantly. – mason Mar 02 '21 at 21:07
  • 1
    There are [directions](https://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html) on the Hangfire site for how to keep an ASP.NET IIS site always running, but it has not been updated for ASP.NET Core. – mason Mar 02 '21 at 21:07
  • 1
    @KhalidAb I just implemented a Blazor Server App and ran into the same problem. It's an IIS configuration. Let me check and I will confirm if the setting is different than the link I provided you. Just so you know this issue has nothing to do with Blazor. It's an IIS configuration issue – Jason D Mar 02 '21 at 21:11
  • @mason thanks for the link, i already tried it(from "Making ASP.NET Core application always running on IIS") but not working... and for your advise, even if i do it with windows service, i will need also to keep my app alive, right? – Khalid Ab Mar 02 '21 at 23:40
  • No, if you do a Windows service, your app will not be killed when idle. It will just keep running, like any other Windows service. [Topshelf](http://topshelf-project.com/) can be used to easily turn a console app into a Windows service. – mason Mar 03 '21 at 00:27
  • 1
    @Khalid Ab, I suggest you look more closely at the solution I proposed. As you can see the default timing for application pool recylcing is 1740 minutes = 29hours. It lines up with your observation. If you don't believe that, you can run event viewer on your web server and you will see IIS recycles the application pool at 29hours. Please make sure you are configuring the correct application pool that is associated with your web service. Of course you will need to let your app run for more than 29 hours before you can know that it is working – Jason D Mar 03 '21 at 12:14

1 Answers1

3

In IIS the application pool recycles every 29 hours by default. This is a configurable setting. Please change the Regular Time Interval (minutes) from 1740 to 0. A setting of 0 means the application pool will never recycle. (see picture for the default setting)

IIS Application Pool Configuration

Changing this setting is helpful for a Blazor Server app, because otherwise clients will get disconnected from the server when the application pool recycles. This is a quirk of SignalR protocol which is used by Blazor Server.

Jason D
  • 1,863
  • 2
  • 16
  • 30
  • Yes you'r right to ask explaination... i just change the setting, i will tell you if its working for me in 29h ;-) thanks @Jason – Khalid Ab Mar 03 '21 at 13:35
  • 1
    So happy to help. Blazor Server has a lot of quirks like this. If you could upvote that would be great! – Jason D Mar 05 '21 at 15:23
  • yes you'r right @Jason D ... and i have another question [here](https://stackoverflow.com/questions/66497457/how-to-restart-blazor-server-side-webapp-on-iis-8-5-after-reboot-server) if you can help it would be perfect haha ... i already did an upvote and also approuved your answer :-) – Khalid Ab Mar 05 '21 at 18:06