fix: improve polling patterns across deployment services#6920
fix: improve polling patterns across deployment services#6920spboyer wants to merge 2 commits intoAzure:mainfrom
Conversation
- Stack deployments: replace constant 5s polling with exponential backoff (1s initial, 10s cap) for both subscription and resource group scoped deployment stack lookups - FuncApp host: fix bug where Retry-After header value was computed but ignored (delay was reassigned to pollDelay instead of retryAfter). Also make 404-retry sleep context-aware. - Static Web App: make deployment verification sleep context-aware so Ctrl+C responds promptly instead of blocking for up to 5s. Addresses findings 10, 11, 12 from Azure#6886 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Improves polling behavior across multiple deployment-related services in the azd CLI to reduce unnecessary API load and make waits responsive to cancellation.
Changes:
- Updated stack deployment polling to use exponential backoff capped at 10s (instead of constant 5s).
- Fixed FuncApp deployment polling to honor
Retry-Afterand made the initial 404 retry sleep context-aware. - Made Static Web App deployment verification sleep context-aware to respond to cancellation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cli/azd/pkg/project/service_target_staticwebapp.go | Replaces fixed sleep with context-aware wait during SWA deployment verification. |
| cli/azd/pkg/azsdk/funcapp_host_client.go | Fixes Retry-After usage and makes polling sleeps cancellation-aware. |
| cli/azd/pkg/azapi/stack_deployments.go | Switches stack deployment polling from constant delay to capped exponential backoff. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if deploymentNotFoundAttempts <= 3 && response.StatusCode == http.StatusNotFound { | ||
| deploymentNotFoundAttempts++ | ||
| time.Sleep(pollDelay) | ||
| select { | ||
| case <-ctx.Done(): | ||
| return PublishResponse{}, ctx.Err() | ||
| case <-time.After(pollDelay): | ||
| } |
There was a problem hiding this comment.
waitForDeployment never closes response.Body from c.pipeline.Do(req). In the 404 retry branch you continue after sleeping without closing, and in the normal path you unmarshal the body but still don't close it. This can leak HTTP connections and eventually stall polling. Close the body on every iteration (including before continue / before returning), without using a plain defer inside the loop (wrap the per-iteration work in an inner func or close explicitly).
Close response.Body on every iteration of the polling loop to prevent HTTP connection leaks. Previously the body was never closed, especially on 404 retry paths where the body was not consumed at all. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
|
Fixed in 1881552 — added explicit
|
Description
Fix polling patterns across three deployment services.
Closes: #6919
Parent: #6886 (Performance Review Audit -- Findings 10, 11, 12)
Changes
Finding 10: Stack Deployments -- Exponential Backoff
pkg/azapi/stack_deployments.go-- bothGetSubscriptionDeploymentandGetResourceGroupDeployment:retry.NewConstant(5*time.Second)->retry.WithCappedDuration(10*time.Second, retry.NewExponential(1*time.Second))Finding 11: FuncApp -- Retry-After Bug Fix
pkg/azsdk/funcapp_host_client.go:delay = pollDelayinstead ofdelay = retryAfterafter computing the Retry-After header value. Now correctly uses the server-provided backoff hint.Finding 12: SWA -- Context-Aware Sleep
pkg/project/service_target_staticwebapp.go:time.Sleep(5 * time.Second)withselect { case <-ctx.Done(): ... case <-time.After(...): }so deployment verification responds to user cancellationCode Review
GetResourceGroupDeploymentupdate (now fixed)Testing
go buildclean