When deploying a Logic App (standard) and the resource doesn't exist, approx every third deployment will fail with a "kudu service unavailable 503" error.
The deployment is done in two steps:
Infrastructure ARM template is deployed using the AzureResourceManagerTemplateDeployment@3 task. The deployment is successful, however:
Stopping/starting the app or changing the App Service Plan fixes this, and the ASP CPU/memory usage is near 0%, which seems to point to an unhandled runtime exception.
In the pipeline, if also deploying the application using AzureFunctionApp@1:
Starting: Deploying Standard Logic App
Task : Azure Functions Deploy
Description : Update a function app with .NET, Python, JavaScript, PowerShell, Java based web applications
Version : 2.238.1
Author : Microsoft Corporation
Help : https://aka.ms/azurefunctiontroubleshooting
Got service connection details for Azure App Service:'logicapp-dev'
NOTE: Function app is VNet integrated.
Deleting App Service Application settings. Data: ["WEBSITE_RUN_FROM_ZIP","WEBSITE_RUN_FROM_PACKAGE"]
App Service Application settings are already present.
Validating deployment package for functions app before Zip Deploy
Package deployment using ZIP Deploy initiated.
##[error]Failed to deploy web package to App Service.
##[warning]Can't find loc string for key: KuduStackTraceURL
##[error]KuduStackTraceURL https://$logicapp-dev:***@logicapp-dev.scm.azurewebsites.net/api/vfs/LogFiles/kudu/trace
##[error]Error: Error: Failed to deploy web package to App Service. Service Unavailable (CODE: 503)
##[warning]Error: Failed to update deployment history. Error: Service Unavailable (CODE: 503)
App Service Application URL: https://logicapp-dev.azurewebsites.net
Finishing: Deploying Standard Logic App
Following the link to the kudu trace logs provides the following:
{
"Message": "An error has occurred.",
"ExceptionMessage": "Illegal characters in path.",
"ExceptionType": "System.ArgumentException",
"StackTrace": " at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)\r\n
at System.IO.Path.Combine(String path1, String path2)\r\n
at Kudu.Services.Infrastructure.VfsControllerBase.GetOriginalLocalFilePath()
in C:\\__w\\1\\s\\Kudu.Services\\Infrastructure\\VfsControllerBase.cs:line 327\r\n
at Kudu.Services.Infrastructure.VfsControllerBase.GetLocalFilePath()
in C:\\__w\\1\\s\\Kudu.Services\\Infrastructure\\VfsControllerBase.cs:line 316\r\n
at Kudu.Services.Infrastructure.VfsControllerBase.GetItem()
in C:\\__w\\1\\s\\Kudu.Services\\Infrastructure\\VfsControllerBase.cs:line 52\r\n
at lambda_method(Closure , Object , Object[] )\r\n
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor
...continued...
}
I've spent about 5 days ruling out the following:
Notes:
Has anyone come across this kudu 503 error before when deploying a Logic App (standard) or Function App?
We've come up with a workaround which is to restart the app service if it's a first-time deployment.
It's not ideal, though Microsoft didn't have any suggestions after an initial conversation.
We could investigate further, but like most developers we don't have unlimited time to be investigating, so have stopped our efforts here.
- task: AzurePowerShell@5
displayName: Check if first time deployment
inputs:
azureSubscription: <subscription>
scriptType: inlineScript
inline: |
$existing = Get-AzWebApp -ResourceGroupName <rg-name> -Name <logic-app-name> -ErrorAction SilentlyContinue
if($existing -eq $null) {
Write-Host "##vso[task.setvariable variable=IS_FIRST_LOA_DEPLOYMENT]true"
}
else {
Write-Host "##vso[task.setvariable variable=IS_FIRST_LOA_DEPLOYMENT]false"
}
azurePowerShellVersion: "LatestVersion"
# App service will sometimes experience an exception here and Kudu will stop responding if being deployed into an environment for the first time
- task: AzureResourceManagerTemplateDeployment@3
displayName: Deploy logic app infra
inputs:
deploymentScope: "Resource Group"
azureResourceManagerConnection: <connection>
subscriptionId: <subscriptionId>
action: "Create Or Update Resource Group"
resourceGroupName: <rg-name>
location: <location>
templateLocation: "Linked artifact"
csmFile: <your-arm-template>
csmParametersFile: <parameter-file>
deploymentMode: "Incremental"
- task: AzurePowerShell@5
displayName: Restart Logic App
condition: eq(variables.IS_FIRST_LOA_DEPLOYMENT, true)
inputs:
azureSubscription: <subscription>
scriptType: inlineScript
inline: |
Restart-AzWebApp -ResourceGroupName <rg-name> -Name <logic-app-name>
azurePowerShellVersion: "LatestVersion"
# allow app service to come back online before attempting to deploy application
- task: AzurePowerShell@5
displayName: Delay 1 minute
condition: eq(variables.IS_FIRST_LOA_DEPLOYMENT, true)
inputs:
azureSubscription: <subscription>
scriptType: inlineScript
azurePowerShellVersion: "LatestVersion"
inline: |
Start-Sleep -Seconds 60
- task: AzureFunctionApp@1
displayName: 'Deploying Standard Logic App'
inputs:
azureSubscription: <subscription>
appType: 'functionApp'
appName: <logic-app-name>
package: <path-to-zip>
deploymentMethod: 'zipDeploy'