Skip to content

Commit

Permalink
Merge pull request #1123 from hashicorp/b/exclude-rm-from-extended-re…
Browse files Browse the repository at this point in the history
…trypolicy

exclude Resource Manager endpoints from network failure detection
  • Loading branch information
jackofallops authored Nov 28, 2024
2 parents 5e0bb9a + 2c5e68d commit 140b04f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
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 !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")
}

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 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
}
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

0 comments on commit 140b04f

Please sign in to comment.