Azure / Azure/azure-powershell

Remove-AzAppServiceEnvironment exits with NotFound error sometimes, but actually the target ASE is removed

Open
#21,215 3 comments 0 reactions 0 assignees View on GitHub
act-observability-squad App Services bug customer-reported Service Attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
3d 14h
Merged PRs (30d)
54

Description

### Description

I am using Powershell and Remove-AzAppServiceEnvironment to remove App Service Environment.
I tried this Module (Remove-AzAppServiceEnvironment) several times and found that sometimes it exited with NotFound error but actually the target ASE is removed. I mean, for example, if I try 5 times, probably 4 successes and 1 NotFound error.

Since I created an automated process to run this command, it is very confused that if it exits with NotFound error. Could you please fix the issue?
**Please see my debug logs for details.**

### Issue script & Debug output
I removed the sensitive information.

```PowerShell
PS C:\Users\testuser> Remove-AzAppServiceEnvironment -ResourceGroupName test-ASEgroup -Name test-ase -Debug

......

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
DELETE

Absolute Uri:
https://management.azure.com/subscriptions/f43ca149-xxxx-xxxx-8fbe-8ca96aafc481/resourceGroups/test-ASEgroup/providers/Microsoft.Web/hostingEnvironments/test-ase?api-version=2021-01-15

Headers:
Accept-Language : en-US
x-ms-client-request-id : bd1741a9-xxxx-xxxx-80ee-02cd1c76e5ef

Body:

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
Accepted

Headers:
Cache-Control : no-cache
Pragma : no-cache
Location : https://management.azure.com/subscriptions/f43ca149-xxxx-xxxx-8fbe-8ca96aafc481/resourceGroups/test-ASEgroup/providers/Microsoft.Web/hostingEnvironments/test-ase/operations/24eb31bb-73ca-4645-a906-6e2c570a7d2c?api-version=2021-01-15
Retry-After : 20
Strict-Transport-Security : max-age=31536000; includeSubDomains
Server : Microsoft-IIS/10.0
X-AspNet-Version : 4.0.30319
X-Powered-By : ASP.NET
x-ms-ratelimit-remaining-subscription-deletes: 14999
x-ms-request-id : 7a68d9aa-xxxx-xxxx-9e22-786daec5c0b1
x-ms-correlation-request-id : 7a68d9aa-xxxx-xxxx-9e22-786daec5c0b1
x-ms-routing-request-id : JAPANWEST:20230313T140953Z:7a68d9aa-xxxx-xxxx-9e22-786daec5c0b1
X-Content-Type-Options : nosniff
Date : Mon, 13 Mar 2023 14:09:53 GMT

Body:

DEBUG: ============================ HTTP REQUEST ============================

......

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/f43ca149-xxxx-xxxx-8fbe-8ca96aafc481/resourceGroups/test-ASEgroup/providers/Microsoft.Web/hostingEnvironments/test-ase/operations/24eb31bb-73ca-4645-a906-6e2c570a7d2c?api-version=2021-01-15

Headers:
x-ms-client-request-id : bd1741a9-xxxx-xxxx-80ee-02cd1c76e5ef

Body:

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
NotFound

Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-failure-cause : gateway
x-ms-request-id : 6c39cfd4-xxxx-xxxx-805f-bbcc0eb1ffe6
x-ms-correlation-request-id : 6c39cfd4-xxxx-xxxx-805f-bbcc0eb1ffe6
x-ms-routing-request-id : JAPANWEST:20230313T143721Z:6c39cfd4-xxxx-xxxx-805f-bbcc0eb1ffe6
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
Date : Mon, 13 Mar 2023 14:37:21 GMT

Body:
{
"error": {
"code": "ResourceNotFound",
"message": "The Resource 'Microsoft.Web/hostingEnvironments/test-ase' under resource group 'test-ASEgroup' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix"
}
}

DEBUG: 23:37:22 - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
Remove-AzAppServiceEnvironment: Long running operation failed with status 'NotFound'.
DEBUG: 23:37:23 - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 23:37:23 - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: AzureQoSEvent: Module: Az.Websites:2.13.0; CommandName: Remove-AzAppServiceEnvironment; PSVersion: 7.3.2; IsSuccess: False; Duration: 00:27:34.4748805; Exception: Long running operation failed with status 'NotFound'.;
DEBUG: 23:37:23 - RemoveAzureAppServiceEnvironmentCmdlet end processing.
PS C:\Users\testuser>
```

### Environment data
- PowerShell-7.3.2-win-x64.msi (https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.3#installing-the-msi-package)

### Module versions
- Azure CLI on Windows 2.46.0 (https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli#install-or-update)
- Azure Az PowerShell module (https://learn.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-9.5.0#installation)

### Error output

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the Remove-AzAppServiceEnvironment cmdlet in Az.Websites and reproduce the DELETE followed by the long-running operation status request shown in the debug log. Confirm that a completed deletion is not reported as a failed NotFound operation, and verify the behavior with an automated removal run.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, powershell
Domain
cloud, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.