Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion sdk/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 !isResourceMangerHost(req) {
return extendedRetryPolicy(r, err)
}

return retryablehttp.DefaultRetryPolicy(ctx, r, err)
}

return false, fmt.Errorf("HTTP response was nil; connection may have been reset")
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 isResourceMangerHost(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
}
2 changes: 1 addition & 1 deletion sdk/go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading