How to safely restart web server on Windows Web App?

Kristian Jakubik 20 Reputation points
2023-12-04T13:20:56.0166667+00:00

Hi,
what is the recommended practice for restarting web app safely? The safe in this context refers to: without downtime, the least request delay, the app is gracefully shutdowned.

Our scenario:
The web app needs to load new updated settings from the app configuration that has been changed. To load the app settings the process needs to be restarted. This is our production environment, so having downtime is not acceptable. On the web app, there is just one web server process running on one instance.

We've already experimented with some possible options and here are our takes

  • Advanced restart in App Service Diagnostics
    • Works without downtime
      • The requests are paused and waiting (30s)
        • No graceful shutdown was observed
  • Changing app service configuration
    • Sometimes 502/503 (<5s) are returned -> downtime
      • In logs there is graceful shutdown
        • Requests are processed at normal speed

What is the recommended approach?

About Web App

  • Windows
  • P2V3
  • ASP.NET Core application
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,960 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ryan Hill 30,281 Reputation points Microsoft Employee Moderator
    2023-12-05T19:17:09.87+00:00

    Hi @Kristian Jakubik

    Advanced Application restart by design is not intended for overlapped. It should be considered more of a task kill to mitigate any process issue. That's why you're seeing that behavior. It's the same for restarting from the portal as well. However, I do echo @TP 's response above in leveraging App Configuration ConfigureRefresh method to register changes.

    If your configuration is rooted in simple App Settings, one approach to consider slot swapping, Set up staging environments - Azure App Service | Microsoft Learn. The advantage here is you can add/remove your application settings within you dev/test slot, route a small percentage of traffic to the slot to verify your changes and then swap the slots.

    Another recommended approach towards maintaining high availability is using a multi-region approach. You can deploy your application to separate regions and place them behind Traffic Manager, Control traffic with Traffic Manager - Azure App Service | Microsoft Learn, where you designate a primary and secondary. Therefore, when you upgrade and restart your app service, traffic manager will redirect to the secondary while the primary is offline and switch back once it becomes available.


1 additional answer

Sort by: Most helpful
  1. TP 125.8K Reputation points Volunteer Moderator
    2023-12-04T19:15:12.2133333+00:00

    Hi Kristian,

    Have you considered modifying your app so that settings can be updated on the fly, without the need to restart? You could make it manually-triggered if you want. Please see article below:

    Tutorial: Use dynamic configuration in an ASP.NET Core app

    https://learn.microsoft.com/en-us/azure/azure-app-configuration/enable-dynamic-configuration-aspnet-core?tabs=core6x

    Please click Accept Answer and upvote if the above was useful.

    Thanks.

    -TP

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.