diff --git a/sdk/client/client.go b/sdk/client/client.go index 52de494374a..d77e8afaf4d 100644 --- a/sdk/client/client.go +++ b/sdk/client/client.go @@ -471,8 +471,13 @@ func (c *Client) Execute(ctx context.Context, req *Request) (*Response, error) { // Check for failed connections etc and decide if retries are appropriate if r == nil { if req.IsIdempotent() { - return extendedRetryPolicy(r, err) + if !isResourceManagerHost(req) { + return extendedRetryPolicy(r, err) + } + + return retryablehttp.DefaultRetryPolicy(ctx, r, err) } + return false, fmt.Errorf("HTTP response was nil; connection may have been reset") } @@ -754,6 +759,7 @@ func containsStatusCode(expected []int, actual int) bool { // extendedRetryPolicy extends the defaultRetryPolicy implementation in go-retryablehhtp with // additional error conditions that should not be retried indefinitely +// TODO - This should be removed as part of 5.0 release of AzureRM, and the base layer returned to the `retryablehttp.DefaultRetryPolicy` for all requests. func extendedRetryPolicy(resp *http.Response, err error) (bool, error) { // A regular expression to match the error returned by net/http when the // configured number of redirects is exhausted. This error isn't typed @@ -840,3 +846,22 @@ func extendedRetryPolicy(resp *http.Response, err error) (bool, error) { return false, nil } + +// exclude Resource Manager calls from the network failure retry avoidance to help users on unreliable networks +// This code path should be removed when the Data Plane separation work is completed and 5.0 ships. +func isResourceManagerHost(req *Request) bool { + knownResourceManagerHosts := []string{ + "management.azure.com", + "management.chinacloudapi.cn", + "management.usgovcloudapi.net", + } + if url := req.Request.URL; url != nil { + for _, host := range knownResourceManagerHosts { + if strings.Contains(url.Host, host) { + return true + } + } + } + + return false +} diff --git a/sdk/go.mod b/sdk/go.mod index a374f001db7..2778249db40 100644 --- a/sdk/go.mod +++ b/sdk/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/go-azure-sdk/sdk -go 1.21 +go 1.22 require ( github.com/Azure/go-autorest/autorest v0.11.29