ResourceModified - Resource Modified: Concurrent Modification Detected
The resource changed between your read and write operations—your ETag is stale because another process modified it concurrently. This 409 client-side error means ARM's optimistic concurrency control rejected the update to prevent lost updates. ARM compares your request's ETag against the current resource ETag; mismatches indicate concurrent modifications. ETags update immediately when resources change, so parallel operations cause conflicts. This is transient—refreshing the ETag and retrying usually works. Common in VM updates, AKS cluster modifications, Azure SQL database changes, and App Service configuration updates when multiple processes modify resources simultaneously.
#Common Causes
- →Concurrent Modification: Another process updates the resource between your read and write operations. ARM updates ETags immediately when resources change, so concurrent modifications cause ETag mismatches. This is transient—getting a fresh ETag and retrying helps.
- →ETag Mismatch: Your If-Match header value doesn't match the current resource.etag. The resource was modified after you retrieved it, indicating another operation changed it concurrently. This is transient—retrying with a fresh ETag helps.
- →Version Conflict: Optimistic concurrency control failure. ARM validates ETags to prevent lost updates—if your ETag is stale, ARM rejects the operation. This is transient when caused by concurrent modifications—retrying with a fresh ETag helps.
✓Solutions
- 1Step 1: Diagnose - Get fresh ETag from the current resource state. GET the resource and extract the ETag from response headers.
- 2Step 2: Diagnose - Compare the ETag in your failed request to the current resource ETag. They should differ if the resource was modified.
- 3Step 3: Fix - Use the read-modify-write pattern: GET the resource, modify it, then PUT with the fresh ETag.
- 4Step 4: Fix - Implement retry logic that catches ResourceModified and refreshes the ETag before retrying.
- 5Step 5: Fix - Always GET the resource before updating to ensure you have the latest ETag.
- 6Step 6: Verify - Retry your operation with the fresh ETag. It should succeed with HTTP 200/201 instead of ResourceModified.
</>Code Examples
1# This script demonstrates handling ResourceModified errors with ETag management
2
3# Step 1: Example resource ID (replace with your actual resource ID)
4RESOURCE_ID="/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Compute/virtualMachines/my-vm"
5echo "Managing ETags for resource: $RESOURCE_ID"
6
7# Step 2: Function to get current ETag (for Storage blobs example)
8get_blob_etag() {
9 local storage_account=$1
10 local container=$2
11 local blob=$3
12 local account_key=$4
13
14 az storage blob show \
15 --account-name $storage_account \
16 --container-name $container \
17 --name $blob \
18 --account-key $account_key \
19 --query "properties.etag" \
20 --output tsv
21}
22
23# Step 3: Retry function with ETag refresh pattern
24retry_with_etag_refresh() {
25 local max_attempts=$1
26 local attempt=1
27 shift 1
28
29 while [ $attempt -le $max_attempts ]; do
30 echo "Attempt $attempt of $max_attempts..."
31
32 # Get fresh ETag before each attempt
33 # Note: This is a demonstration - actual implementation depends on resource type
34 echo "Getting fresh ETag..."
35
36 # Perform operation with fresh ETag
37 # If operation fails with ResourceModified, retry with fresh ETag
38 if [ $attempt -lt $max_attempts ]; then
39 echo "Waiting before retry..."
40 sleep 1
41 attempt=$((attempt + 1))
42 else
43 echo "Max attempts reached"
44 break
45 fi
46 done
47}
48
49# Step 4: Instructions for read-modify-write pattern
50echo ""
51echo "Read-Modify-Write Pattern:"
52echo " 1. GET the resource to obtain current ETag"
53echo " 2. Modify the resource locally"
54echo " 3. PUT the resource with If-Match header containing the ETag"
55echo " 4. If you get ResourceModified, repeat from step 1"
56echo ""
57echo "Example REST API flow:"
58echo " GET /subscriptions/{sub-id}/resourceGroups/{rg}/providers/..."
59echo " Response: { ..., "etag": "\"0x8D...\"" }"
60echo ""
61echo " PUT /subscriptions/{sub-id}/resourceGroups/{rg}/providers/..."
62echo " Headers:"
63echo " If-Match: "0x8D...""
64echo " Authorization: Bearer <token>"
65echo ""
66echo " If 409 ResourceModified:"
67echo " GET again for fresh ETag"
68echo " Retry PUT with fresh ETag"↗Related Errors
Provider Information
This error code is specific to AZURE services. For more information, refer to the official AZURE documentation.