ARM Template MSDeploy Race Condition Issue


In Azure Resource Manager ARM Templates, you describe all the resources needed for your project. One of which could be an Azure App Service. For Azure App Services you can add an MSDeploy Resource, that describes what to publish to the app service. You could also define App Settings, Site Configurations, Connection Strings and many more. For more information about ARM Templates please visit the documentation here https://azure.microsoft.com/en-us/documentation/articles/resource-group-authoring-templates/.

In this post I will touch upon a scenario that might disrupt the flow of a template when dealing with an App Service, MSDeploy with other App configs (App Settings, Site Configurations, or Connection Strings). There are 2 manifestations of the problem:

1- An error from MSDeploy, something like "Deployment was interrupted and the process running it was terminated unexpectedly,..."

2- The deployment hangs and takes a lot of time to fail.

The reason behind this problem is a race condition caused by how the resources are ordered. App Settings changes or connection string changes cause a site restart Asynchronously, if MSDeploy goes after that step, then there is no guarantee that the site will not restart during the deployment. But if you make all steps depend on MSDeploy then you ensure MSDeploy runs first and then any other site restarting activities.

 

TemplateSnippet

 

A working example of WordPress deployment template that is implementing this could be found here 

Comments (2)
  1. Rik van den Berg says:

    Hi Hosam, Thanks for clearing that up. I have one question though, is there a chance that for example Application_Start code in Global.asax is run before the configuration is deployed? Kind Regards, Rik

    1. Hosam Shobak says:

      Hi Rik,
      sorry for the late reply, but there is no easy way to do this using the current MSDeploy flow, I would suggest that you look at Kudu and the deployment scripts that allows you to run some code before the deployment really happens you can find more information about Kudu here https://github.com/projectkudu/kudu/wiki and specific information about custom deployment scripts you can find more information here: https://github.com/projectkudu/kudu/wiki/Deployment-hooks

Comments are closed.

Skip to main content