Compare commits

...

1 Commits

Author SHA1 Message Date
ryanfkeepers
64a122413b customize tcp handshake timeouts
shot in the dark at avoiding tcp read timeouts by
extending the tcp dialer and tls handshake timeouts
in the graph client transport.
2023-05-12 15:47:56 -06:00
2 changed files with 24 additions and 12 deletions

View File

@ -37,7 +37,7 @@ func NewHTTPWrapper(opts ...Option) *httpWrapper {
rt = customTransport{
n: pipeline{
middlewares: internalMiddleware(cc),
transport: defaultTransport(),
transport: defaultHttpTransport(),
},
}
redirect = func(req *http.Request, via []*http.Request) error {
@ -132,13 +132,6 @@ func (pl pipeline) Next(req *http.Request, idx int) (*http.Response, error) {
return pl.transport.RoundTrip(req)
}
func defaultTransport() http.RoundTripper {
defaultTransport := http.DefaultTransport.(*http.Transport).Clone()
defaultTransport.ForceAttemptHTTP2 = true
return defaultTransport
}
func internalMiddleware(cc *clientConfig) []khttp.Middleware {
mw := []khttp.Middleware{
&RetryMiddleware{

View File

@ -1,6 +1,7 @@
package graph
import (
"net"
"net/http"
"time"
@ -150,12 +151,14 @@ func GetAuth(tenant string, client string, secret string) (*kauth.AzureIdentityA
// can utilize it on a per-download basis.
func KiotaHTTPClient(opts ...Option) *http.Client {
var (
clientOptions = msgraphsdkgo.GetDefaultClientOptions()
cc = populateConfig(opts...)
middlewares = kiotaMiddlewares(&clientOptions, cc)
httpClient = msgraphgocore.GetDefaultClient(&clientOptions, middlewares...)
clientOptions = msgraphsdkgo.GetDefaultClientOptions()
cc = populateConfig(opts...)
middlewares = kiotaMiddlewares(&clientOptions, cc)
httpClient = msgraphgocore.GetDefaultClient(&clientOptions, middlewares...)
customTransport = khttp.NewCustomTransportWithParentTransport(defaultHttpTransport(), middlewares...)
)
httpClient.Transport = customTransport
httpClient.Timeout = defaultHTTPClientTimeout
cc.apply(httpClient)
@ -163,6 +166,22 @@ func KiotaHTTPClient(opts ...Option) *http.Client {
return httpClient
}
func defaultHttpTransport() *http.Transport {
defaultTransport := khttp.GetDefaultTransport().(*http.Transport).Clone()
// default: 10 seconds
defaultTransport.TLSHandshakeTimeout = 30 * time.Second
// default: 30 seconds
nd := &net.Dialer{
Timeout: 60 * time.Second,
KeepAlive: 60 * time.Second,
}
defaultTransport.DialContext = nd.DialContext
return defaultTransport
}
// ---------------------------------------------------------------------------
// HTTP Client Config
// ---------------------------------------------------------------------------