Extend timeout for graceful shutdown in Azure App Service

Mo Becker 11 Reputation points
2022-12-12T12:11:28.097+00:00

Setup

I am using IHostApplicationLifetime.ApplicationStopping.Register() to register a method for gracefully shutting down an App Service (.NET 6.0, Windows 64 Bit, managed pipeline version: "Integrated"). For testing purposes, I added the following loop to the callback method to simulate a slow shutdown:

for (int i = 0; i < 120; i++)  
{  
    Thread.Sleep(TimeSpan.FromSeconds(1));  
    NLogLogger.Instance.Info($"Waited {(i + 1) * 1} s.");  
}  

Problem

Clicking the stop button on the App Service's page in the Azure Portal kills the process after approximately 30 s, as can be seen from the log file. The desired behavior would be to see the full 120 s logged in the log file.

What I tried so far

Increasing shutdown timeout in Program.Main:

WebHost.CreateDefaultBuilder(args)  
    .UseShutdownTimeout(TimeSpan.FromMinutes(10)) // give enough time for graceful shutdown  
    .UseStartup
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,977 questions
{count} votes

1 answer

Sort by: Most helpful
  1. brtrach-MSFT 17,741 Reputation points Microsoft Employee Moderator
    2022-12-19T01:42:38.47+00:00

    @Mo Becker We understand you are attempting to adjust the graceful shutdown period of your web app from 30s to 120s.

    It is not supported on multi-tenant app services to configure the shutdown period. As a result, you would need to deploy your app into a container to be able to gain this level of control.

    We invite you to make the feature request here. This might be a hard limitation due to the public nature of the mutli-tenant app service, but it would be a good idea to share your feedback/usage requirement directly with the product group.


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.