diff --git a/cli/azd/pkg/azapi/stack_deployments.go b/cli/azd/pkg/azapi/stack_deployments.go index f410d83a255..c9197d6b2ac 100644 --- a/cli/azd/pkg/azapi/stack_deployments.go +++ b/cli/azd/pkg/azapi/stack_deployments.go @@ -125,7 +125,10 @@ func (d *StackDeployments) GetSubscriptionDeployment( err = retry.Do( ctx, - retry.WithMaxDuration(10*time.Minute, retry.NewConstant(5*time.Second)), + retry.WithMaxDuration( + 10*time.Minute, + retry.WithCappedDuration(10*time.Second, retry.NewExponential(1*time.Second)), + ), func(ctx context.Context) error { response, err := client.GetAtSubscription(ctx, deploymentName, nil) if err != nil { @@ -201,7 +204,10 @@ func (d *StackDeployments) GetResourceGroupDeployment( err = retry.Do( ctx, - retry.WithMaxDuration(10*time.Minute, retry.NewConstant(5*time.Second)), + retry.WithMaxDuration( + 10*time.Minute, + retry.WithCappedDuration(10*time.Second, retry.NewExponential(1*time.Second)), + ), func(ctx context.Context) error { response, err := client.GetAtResourceGroup(ctx, resourceGroupName, deploymentName, nil) if err != nil { diff --git a/cli/azd/pkg/azsdk/funcapp_host_client.go b/cli/azd/pkg/azsdk/funcapp_host_client.go index d7b3431747d..89622229b74 100644 --- a/cli/azd/pkg/azsdk/funcapp_host_client.go +++ b/cli/azd/pkg/azsdk/funcapp_host_client.go @@ -138,8 +138,13 @@ func (c *FuncAppHostClient) waitForDeployment(ctx context.Context, location stri } if deploymentNotFoundAttempts <= 3 && response.StatusCode == http.StatusNotFound { + response.Body.Close() deploymentNotFoundAttempts++ - time.Sleep(pollDelay) + select { + case <-ctx.Done(): + return PublishResponse{}, ctx.Err() + case <-time.After(pollDelay): + } continue } @@ -149,19 +154,24 @@ func (c *FuncAppHostClient) waitForDeployment(ctx context.Context, location stri // This 404 is due to the deployment worker being "recycled". // This shortcoming would be fixed by work item https://msazure.visualstudio.com/Antares/_workitems/edit/24715654. if response.StatusCode == http.StatusNotFound && lastResponse != nil { + response.Body.Close() return *lastResponse, nil } if response.StatusCode != http.StatusAccepted && response.StatusCode != http.StatusOK { - return PublishResponse{}, runtime.NewResponseError(response) + err := runtime.NewResponseError(response) + response.Body.Close() + return PublishResponse{}, err } // Server always returns status code of OK-200 whether the deployment is in-progress or complete. // Thus, we always read the response body to determine the actual status. resp := PublishResponse{} if err := runtime.UnmarshalAsJSON(response, &resp); err != nil { + response.Body.Close() return PublishResponse{}, err } + response.Body.Close() switch resp.Status { case PublishStatusCancelled: @@ -181,7 +191,7 @@ func (c *FuncAppHostClient) waitForDeployment(ctx context.Context, location stri delay := pollDelay if retryAfter := httputil.RetryAfter(response); retryAfter > 0 { - delay = pollDelay + delay = retryAfter } select { diff --git a/cli/azd/pkg/project/service_target_staticwebapp.go b/cli/azd/pkg/project/service_target_staticwebapp.go index ec3167cdd44..291f3124a42 100644 --- a/cli/azd/pkg/project/service_target_staticwebapp.go +++ b/cli/azd/pkg/project/service_target_staticwebapp.go @@ -290,7 +290,11 @@ func (at *staticWebAppTarget) verifyDeployment(ctx context.Context, targetResour return fmt.Errorf("failed verifying static web app deployment. Still in %s state", envProps.Status) } - time.Sleep(5 * time.Second) + select { + case <-ctx.Done(): + return ctx.Err() + case <-time.After(5 * time.Second): + } } return nil