Repository navigation
pkg/httputil: configure HTTP transport timeouts - #645
Conversation
|
cc @AkihiroSuda |
| } | ||
|
|
||
| dialer := &net.Dialer{ | ||
| Timeout: 30 * time.Second, |
There was a problem hiding this comment.
Should this be passed from the caller as an option like WithTimeout() ?
There was a problem hiding this comment.
Don't think so (or at least it would be a separate feature) I used the same defaults as http.DefaultTransport. Or at least to my understanding, this client is created as the equivalent to the default, but with the connection-string modified.
For timeouts, callers can already use context cancellation.
Same for the other timeout, which also aligns with stdlib.
There was a problem hiding this comment.
I used the same defaults as http.DefaultTransport
Please add a comment line to refer to it?
There was a problem hiding this comment.
Updated; I slightly rewrote the code, and added a unixDialContext helper, so that the code here more closely resembles the implementation of http.DefaultTransport in stdlib;
var DefaultTransport RoundTripper = &Transport{
Proxy: ProxyFromEnvironment,
DialContext: defaultTransportDialContext(&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}),
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}| return d.DialContext(ctx, "unix", socketPath) | ||
| return dialer.DialContext(ctx, "unix", socketPath) | ||
| }, | ||
| IdleConnTimeout: 90 * time.Second, |
There was a problem hiding this comment.
maybe:
| IdleConnTimeout: 90 * time.Second, | |
| IdleConnTimeout: dialer.Timeout * 3 |
a93c120 to
bb7bd35
Compare
Configure a timeout for connecting to the RootlessKit API socket, and set an idle connection timeout on the HTTP transport. Previously, idle connections had no expiration because IdleConnTimeout was left at its zero value. This could leave connections open indefinitely for callers that create short-lived clients without explicitly closing idle connections. Use the same dial and idle connection timeouts as http.DefaultTransport. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
bb7bd35 to
fc7dfe1
Compare
Configure a timeout for connecting to the RootlessKit API socket, and set an idle connection timeout on the HTTP transport.
Previously, idle connections had no expiration because IdleConnTimeout was left at its zero value. This could leave connections open indefinitely for callers that create short-lived clients without explicitly closing idle connections.
Use the same dial and idle connection timeouts as http.DefaultTransport.