Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse http client used with ASM API #3858

Merged
merged 5 commits into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
12 changes: 10 additions & 2 deletions services/classic/management/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package management
import (
"errors"
"fmt"
"net/http"
"runtime"
"time"

Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions services/classic/management/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/tls"
"fmt"
"net/http"
"time"
)

const (
Expand Down Expand Up @@ -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
}
Expand All @@ -111,7 +107,7 @@ func (client client) createHTTPClient() (*http.Client, error) {
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{
Renegotiation: tls.RenegotiateOnceAsClient,
Renegotiation: tls.RenegotiateFreelyAsClient,
jhendrixMSFT marked this conversation as resolved.
Show resolved Hide resolved
Certificates: []tls.Certificate{cert},
},
},
Expand Down Expand Up @@ -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 {
jhendrixMSFT marked this conversation as resolved.
Show resolved Hide resolved
// Wait before retrying the operation
time.Sleep(30 * time.Second)
jhendrixMSFT marked this conversation as resolved.
Show resolved Hide resolved
}

return client.sendRequest(httpClient, url, requestType, contentType, data, numberOfRetries-1)
}
Expand Down