diff --git a/services/classic/management/client.go b/services/classic/management/client.go index 5d75b73a754f..6d3d350b6e47 100644 --- a/services/classic/management/client.go +++ b/services/classic/management/client.go @@ -21,6 +21,7 @@ package management import ( "errors" "fmt" + "net/http" "runtime" "time" @@ -44,6 +45,7 @@ const ( type client struct { publishSettings publishSettings config ClientConfig + httpClient *http.Client } // Client is the base Azure Service Management API client instance that @@ -154,10 +156,16 @@ func makeClient(subscriptionID string, managementCert []byte, config ClientConfi config.UserAgent = DefaultUserAgent } - return client{ + clientObj := client{ publishSettings: publishSettings, config: config, - }, nil + } + var err error + clientObj.httpClient, err = clientObj.createHTTPClient() + if err != nil { + return nil, err + } + return clientObj, nil } func userAgent() string { diff --git a/services/classic/management/http.go b/services/classic/management/http.go index 3573010017af..a12f8a156ded 100644 --- a/services/classic/management/http.go +++ b/services/classic/management/http.go @@ -21,6 +21,7 @@ import ( "crypto/tls" "fmt" "net/http" + "time" ) const ( @@ -86,12 +87,7 @@ func (client client) sendAzureRequest(method, url, contentType string, data []by return nil, fmt.Errorf(errParamNotSpecified, "url") } - httpClient, err := client.createHTTPClient() - if err != nil { - return nil, err - } - - response, err := client.sendRequest(httpClient, url, method, contentType, data, 5) + response, err := client.sendRequest(client.httpClient, url, method, contentType, data, 5) if err != nil { return nil, err } @@ -161,6 +157,10 @@ func (client client) sendRequest(httpClient *http.Client, url, requestType, cont if numberOfRetries == 0 { return nil, azureErr } + if response.StatusCode == http.StatusServiceUnavailable || response.StatusCode == http.StatusTooManyRequests { + // Wait before retrying the operation + time.Sleep(client.config.OperationPollInterval) + } return client.sendRequest(httpClient, url, requestType, contentType, data, numberOfRetries-1) }