Azure infrastructure bug: automatic restart of App Service without graceful shutdown

Mo Becker 11 Reputation points
2023-02-22T20:43:59.9266667+00:00

We are running an Azure App Service (Single Instance, S1, Windows, 64 bit, .NET 6, Always On enabled, Health Check disabled, Auto Heal disabled) where it is extremely important for data integrity that the service only terminates after a graceful shutdown. The graceful shutdown is implemented via IHostApplicationLifetime.ApplicationStopping, which is working fine (e.g. when the stop button is pressed in the Azure portal).

However, our log files (as well as the eventLog.xml) show that on 1/27/2023 at 3:25 UTC a new instance of the application was started, but the old instance was terminated without a graceful shutdown. In fact, the log file shows that the callback registered with ApplicationStopping was not entered at all, so it looks like the process was just abruptly killed.

The "Diagnose and solve problems - Web App Restarted" tool showed the following information:

Around 1/27/2023 3:25:23 AM (UTC), on Instance DW1SDWK0008DH, your application was recycled as there was a movement of your application from an existing worker instance because Azure platform detected that the worker instance was not working as expected. This resulted in your application being provisioned and started on a new VM instance.

All other health values during the time were normal, and there was nothing in the log suggesting that the application was not "working as expected". [Edit: I have now observed the same behavior due to "normal" Azure infrastructure maintenance/update events.]

    1. Is it a bug in the Azure App Service infrastructure that the ApplicationStopping callback was not called on the instance to be replaced?
  1. If graceful shutdown cannot be guaranteed under all circumstances, App Services may not be the right solution for our application. In that case, is there something more suitable?
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,933 questions
{count} votes

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.