Skip to content

Fix infinite retry loop in SetResource.ps1 (missing $iterator increment) - #198

Open
madanmishra1223 wants to merge 1 commit into
microsoft:masterfrom
madanmishra1223:fix/setresource-retry-loop
Open

Fix infinite retry loop in SetResource.ps1 (missing $iterator increment)#198
madanmishra1223 wants to merge 1 commit into
microsoft:masterfrom
madanmishra1223:fix/setresource-retry-loop

Conversation

@madanmishra1223

Copy link
Copy Markdown

Problem

UpdateLoop in .ci/scripts/SetResource.ps1 is meant to retry a failing Set-AzResource call a bounded number of times:

$success = $false
$iterator = 1

while( ($success -eq $false) -and ($iterator -le $maxIterations))
{
    try
    {
        ...
        $success = $true
        break
    }
    catch
    {
        Write-Host("Failed to write resource update - ")
        Write-Host($_.Exception.Message)
        Start-Sleep -Seconds 5
    }
}

if($success -eq $false)
{
    throw "Failed to update resources"
}

$iterator is initialized to 1 but is never incremented. When Set-AzResource keeps failing, $success stays $false and $iterator stays 1, so the guard ($iterator -le $maxIterations) is always true.

Consequences:

  • The retry budget the caller passes (UpdateLoop -maxIterations 3 -resource $_) is ignored.
  • A resource that can never be tagged (deleted mid-run, insufficient permissions, a provider that rejects the tag) makes the loop spin forever, sleeping 5 seconds and printing the same error each time, until the pipeline job hits its own timeout.
  • The throw "Failed to update resources" below the loop is unreachable on persistent failure, so a genuine failure is reported as a hung/timed-out job instead of a clear error.

Fix

Increment $iterator in the catch block, so the loop honors -maxIterations and a persistent failure exits via the existing throw.

             Write-Host($_.Exception.Message)
+            $iterator++
             Start-Sleep -Seconds 5

One line changed; no behavior change on the success path (that path still breaks on the first successful call).

UpdateLoop initializes $iterator to 1 but never increments it, so the
loop guard ($iterator -le $maxIterations) stays true forever whenever
Set-AzResource keeps failing. Instead of giving up after maxIterations
attempts, the function retries indefinitely with a 5 second sleep
between tries, hanging the pipeline task, and the
"Failed to update resources" throw below the loop is unreachable.

Increment $iterator in the catch block so the retry budget passed by
the caller (-maxIterations 3) is honored and a persistent failure
surfaces as an error instead of a hang.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@madanmishra1223

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants