Home > OS >  Azure Web App Instance Swap causes app threads to stop
Azure Web App Instance Swap causes app threads to stop

Time:08-27

I have a Blazor app written in .NET6 which is generating threads from system.threading.timer to transfer data from multiple tenant-databases to a single group-database. The Application is running fine for up to 4,5,6 hours and then the threads are stopping without showing any error/exception message on the application side or in the webserver side.

By the way, I know that the threads are not working as I have internal logging inside the application for every start and stop of a thread and also from some table data which seems intact.

My service plan is the S1 with one instance and without auto-scaling. Reading couple of Azure Logs I concluded that the application is swapping instances from one to another while is being loaded (not overloaded) and that causes the threads to top, although from the screenshots below seems that something still is active.

Here is the CPU of the instances, as you can notice an instance swapping is happening around 18:10-18:20 enter image description here

The time that the instance swap happened the application threads were stopped, this can be seen from the database's instance cpu which manipulates. enter image description here

In addition, from Azure WebApp logs seems clearly that instance swapping is happening for real even with one instance configured. enter image description here

Here are a few questions:

  1. Does it really perform instance swapping and why?
  2. Does the instance swapping causing threads to stop?
  3. If the above are true, is there any way to generate threads that are handled by multiple instances or during swapping?.

CodePudding user response:

After some investigation seems that for statefull applications (like this one with an active ThreadPool) while hosted in Azure Web Services need to be instructed to use the same machine.

To do this use the switch "ARR Affinity", this should be switched to off. Otherwise the website will be transferred again and again in different machines.

  • Related