-
Notifications
You must be signed in to change notification settings - Fork 1k
[azcosmos] tighten default HTTP client timeouts and increase pool size #26856
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
74e164a
[azcosmos] tighten default HTTP client timeouts and increase pool size
tvaron3 71541b4
Update CHANGELOG entry: drop 'end-to-end', add PR link
tvaron3 039b99e
Update CHANGELOG PR link to upstream PR 26856
tvaron3 91168b7
[azcosmos] address review feedback on default HTTP client
tvaron3 df0273c
Condense CHANGELOG entry to a single bullet
tvaron3 c746b77
[azcosmos] address PR review: lint fix, WASM dialer, doc accuracy
tvaron3 71b793b
[azcosmos] increase default idle connection pool size
tvaron3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package azcosmos | ||
|
|
||
| import ( | ||
| "crypto/tls" | ||
| "net" | ||
| "net/http" | ||
| "time" | ||
|
|
||
| "golang.org/x/net/http2" | ||
| ) | ||
|
|
||
| const ( | ||
| // defaultConnectTimeout is the default timeout for establishing a new TCP | ||
| // connection to the Cosmos service. | ||
| defaultConnectTimeout = 5 * time.Second | ||
|
|
||
| // defaultRequestTimeout is the default end-to-end timeout applied by the | ||
| // HTTP client to a single request, including connection setup, sending the | ||
| // request, and reading the entire response body. Callers that need a | ||
| // different bound can supply their own Transport via ClientOptions. | ||
| defaultRequestTimeout = 65 * time.Second | ||
| ) | ||
|
|
||
| // defaultCosmosHTTPClient is the http.Client used by Cosmos clients when the | ||
| // caller does not provide a custom Transport via ClientOptions. It mirrors the | ||
| // azcore default transport but uses Cosmos-specific connect and request | ||
| // timeouts. | ||
| var defaultCosmosHTTPClient *http.Client | ||
|
|
||
| func init() { | ||
| defaultCosmosHTTPClient = newDefaultCosmosHTTPClient() | ||
| } | ||
|
|
||
| func newDefaultCosmosHTTPClient() *http.Client { | ||
| transport := &http.Transport{ | ||
| Proxy: http.ProxyFromEnvironment, | ||
| DialContext: (&net.Dialer{ | ||
| Timeout: defaultConnectTimeout, | ||
| KeepAlive: 30 * time.Second, | ||
| }).DialContext, | ||
| ForceAttemptHTTP2: true, | ||
|
tvaron3 marked this conversation as resolved.
|
||
| MaxIdleConns: 1000, | ||
| MaxIdleConnsPerHost: 1000, | ||
| IdleConnTimeout: 90 * time.Second, | ||
| TLSHandshakeTimeout: 10 * time.Second, | ||
| ExpectContinueTimeout: 1 * time.Second, | ||
| TLSClientConfig: &tls.Config{ | ||
| MinVersion: tls.VersionTLS12, | ||
| Renegotiation: tls.RenegotiateFreelyAsClient, | ||
| }, | ||
| } | ||
| if http2Transport, err := http2.ConfigureTransports(transport); err == nil { | ||
| http2Transport.ReadIdleTimeout = 2 * time.Second | ||
| http2Transport.PingTimeout = 1 * time.Second | ||
| } | ||
| return &http.Client{ | ||
| Transport: transport, | ||
| Timeout: defaultRequestTimeout, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package azcosmos | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
| "github.com/Azure/azure-sdk-for-go/sdk/internal/mock" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestDefaultCosmosHTTPClient_Timeouts(t *testing.T) { | ||
| require.Equal(t, 5*time.Second, defaultConnectTimeout) | ||
| require.Equal(t, 65*time.Second, defaultRequestTimeout) | ||
|
|
||
| c := newDefaultCosmosHTTPClient() | ||
| require.NotNil(t, c) | ||
| require.Equal(t, defaultRequestTimeout, c.Timeout) | ||
|
|
||
| transport, ok := c.Transport.(*http.Transport) | ||
| require.True(t, ok, "expected *http.Transport, got %T", c.Transport) | ||
| require.NotNil(t, transport.DialContext) | ||
| } | ||
|
|
||
| func TestWithDefaultTransport_NilOptions(t *testing.T) { | ||
| got := withDefaultTransport(nil) | ||
| require.NotNil(t, got) | ||
| require.Same(t, defaultCosmosHTTPClient, got.Transport) | ||
| } | ||
|
|
||
| func TestWithDefaultTransport_NoTransportSet(t *testing.T) { | ||
| in := &ClientOptions{ | ||
| EnableContentResponseOnWrite: true, | ||
| } | ||
| got := withDefaultTransport(in) | ||
| require.NotSame(t, in, got, "expected withDefaultTransport to clone options") | ||
| require.Nil(t, in.Transport, "caller-supplied options must not be mutated") | ||
| require.Same(t, defaultCosmosHTTPClient, got.Transport) | ||
| require.True(t, got.EnableContentResponseOnWrite) | ||
| } | ||
|
|
||
| func TestWithDefaultTransport_PreservesCallerTransport(t *testing.T) { | ||
| srv, close := mock.NewServer() | ||
| defer close() | ||
|
|
||
| in := &ClientOptions{ | ||
| ClientOptions: azcore.ClientOptions{Transport: srv}, | ||
| } | ||
| got := withDefaultTransport(in) | ||
| require.Same(t, in, got, "expected withDefaultTransport to return same options when Transport is provided") | ||
| require.Same(t, srv, got.Transport) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.