azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

New-AzureResourceGroupDeployment fails with "Task was cancelled" when too many Microsoft.Resources/deployments in the resource group

Open antmeehan opened this issue 10 years ago • 14 comments

I'm not sure what the hard limit is but I've definitely been able to recreate this issue. If you have a large number of Microsoft.Resources/deployments resources in a resource group, the New-AzureResourceGroupDeployment command fails:

2016-05-19T05:03:52.9893465Z ##[debug]5:03:52 AM - NewAzureResourceGroupDeploymentCommand end processing.
2016-05-19T05:03:52.9893465Z ##[debug]5:03:52 AM - NewAzureResourceGroupDeploymentCommand end processing.
2016-05-19T05:03:53.0205961Z ##[error]System.Threading.Tasks.TaskCanceledException: A task was canceled.
2016-05-19T05:03:53.0205961Z ##[error]   at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
2016-05-19T05:03:53.0205961Z ##[error]   at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
2016-05-19T05:03:53.0205961Z ##[error]   at Microsoft.Azure.Management.Resources.DeploymentOperationsExtensions.Validate(IDeploymentOperations operations, String resourceGroupName, String deploymentName, Deployment parameters)
2016-05-19T05:03:53.0205961Z ##[error]   at Microsoft.Azure.Commands.Resources.Models.ResourcesClient.CheckBasicDeploymentErrors(String resourceGroup, String deploymentName, Deployment deployment)
2016-05-19T05:03:53.0205961Z ##[error]   at Microsoft.Azure.Commands.Resources.Models.ResourcesClient.ExecuteDeployment(CreatePSResourceGroupDeploymentParameters parameters)
2016-05-19T05:03:53.0205961Z ##[error]   at Microsoft.Azure.Commands.Resources.NewAzureResourceGroupDeploymentCommand.<>c__DisplayClass3.<ExecuteCmdlet>b__1()
2016-05-19T05:03:53.0205961Z ##[error]   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ConfirmAction(Boolean force, String actionMessage, String processMessage, String target, Action action)
2016-05-19T05:03:53.0205961Z ##[error]   at Microsoft.Azure.Commands.Resources.NewAzureResourceGroupDeploymentCommand.ExecuteCmdlet()
2016-05-19T05:03:53.0205961Z ##[error]   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()

With $DebugPreference="Continue" turned on I can see it is failing on the validate step:

2016-05-19T05:03:52.3543443Z ##[debug]============================ HTTP REQUEST ============================
2016-05-19T05:03:52.3543443Z HTTP Method:
2016-05-19T05:03:52.3543443Z POST
2016-05-19T05:03:52.3543443Z Absolute Uri:
2016-05-19T05:03:52.3543443Z https://management.azure.com/subscriptions/***/resourcegroups/**/providers/microsoft.resources/deployments/apps.azuredeploy-20160519-0458/validate?api-version=2016-02-01
2016-05-19T05:03:52.3543443Z Headers:
2016-05-19T05:03:52.3543443Z Body:

(The response is never received).

If I delete all the Microsoft.Resources/deployments resources using the following PowerShell/ARMClient:

(([string] (armclient GET "https://management.azure.com/subscriptions/****/resourceGroups/***/providers/Microsoft.Resources/deployments?api-version=2015-11-01" )) | ConvertFrom-Json).value | foreach { armclient delete "$($_.id)?api-version=2015-11-01" }

It will then work correctly.

Is there an expected behaviour here? Should I be cleaning up the Microsoft.Resources/deployments resources?

Thanks.

antmeehan avatar May 19 '16 07:05 antmeehan

@antmeehan - Can you please share the co-relation ID/trackingID for this deployment?

ravbhatnagar avatar May 20 '16 06:05 ravbhatnagar

@ravbhatnagar There is no response from the HTTP POST so I can't see a x-ms-correlation-request-id header. Is that what I should be looking for?

antmeehan avatar May 20 '16 06:05 antmeehan

@antmeehan - Apologies for the delayed response.

There is a limit of 800 deployments per resource group. I think you might be running into that limit. How frequently are you running into this limit? Also, are you using a different deployment name for every deployment to the same resource group?

ravbhatnagar avatar Jun 02 '16 00:06 ravbhatnagar

@ravbhatnagar We were using a different name for each resource group template (using the version number as a suffix). We've now moved away from this (just overriding the deployment resource and ensuring the contentVersion value is correct) and the issue seems to have been resolved.

We are creating a new deployment resource for the 'master' resource group template as part of using VSTS task (in fact it was my change in https://github.com/Microsoft/vsts-tasks/pull/1388), but that also matches the Visual Studio experience. So we will still hit this issue eventually (especially in our Continuous Integration environment).

Obviously we would like a better exception from the CmdLet.

Thanks for your help.

antmeehan avatar Jun 02 '16 01:06 antmeehan

Yes, we will look into improving the error message in this scenario.

You will have to do build some logic into your script to clean up older deployments. Or have some workflow which runs periodically and cleans up the deployments (using Remove-AzureRmResourceGroupDeployment cmdlet)

ravbhatnagar avatar Jun 02 '16 21:06 ravbhatnagar

Great. Thanks for your help again.

antmeehan avatar Jun 03 '16 02:06 antmeehan

Need a better error message when 800 deployment limit is hit for the RG. Currently we see a task was cancelled in the client.

ravbhatnagar avatar Nov 10 '16 08:11 ravbhatnagar

We are now getting this issue. New resourcegroup. 9 deployment templates co-relationid is

01:18:38 - [ERROR] New-AzureRmResourceGroupDeployment : Encountered internal server error. 01:18:38 - [ERROR] Diagnostic information: timestamp '20170121T091835Z', subscription id 01:18:38 - [ERROR] '46366488-8b43-4110-8318-9f512806d6cf', tracking id 01:18:38 - [ERROR] '306612b6-f8d6-428a-a26b-07f0fdcacc9d', request correlation id 01:18:38 - [ERROR] '306612b6-f8d6-428a-a26b-07f0fdcacc9d'.

We can reproduce this consistently. comment out one deployment template and it deploys fine. Uncomment we get the above error.

consultguru avatar Jan 21 '17 09:01 consultguru

@ravbhatnagar ,

Executing the New-AzureRmResourceGroupDeployment and failed with the below errors.

Encountered internal server error. Diagnostic information: timestamp '20170731T215157Z', subscription id '5546fd2b-9361-4243-815b-95911090c181', tracking id '1e517b8a-427b-431e-b449-602453472788', request correlation id '1e517b8a-427b-431e-b449-602453472788'. Can you please check what exactly failed the validation?

We are expecting get some meaningful error message rather than Internal Server Error in such scenario, is this achievable in the future release?

huajunzhao avatar Aug 01 '17 08:08 huajunzhao

@huajunzhao - we are investigating this issue and will get back to you.

ravbhatnagar avatar Aug 02 '17 08:08 ravbhatnagar

@huajunzhao - Will it be possible for you to share the template where you are running into this issue? It will help us identify the issue.

ravbhatnagar avatar Aug 03 '17 08:08 ravbhatnagar

@ravbhatnagar ping

cormacpayne avatar Jul 10 '18 21:07 cormacpayne

Can you please update the error message reported? This max of 800 deployments is a common occurrence in our environment Thanks in advance!

webbexpert avatar Jan 25 '19 21:01 webbexpert

Happy to announce that the 800 deployment issue is going to be addressed in a month. The change is getting rolled out: https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/deployment-history-deletions?tabs=azure-powershell so this issue is closed.

satyavel avatar May 28 '20 20:05 satyavel