Skip to content
Snippets Groups Projects
Commit 1c13d4b0 authored by Tomasz Maczukin's avatar Tomasz Maczukin :speech_balloon:
Browse files

Merge branch 'use-keep-alives-everywhere' into 'master'

Properly configure connection timeouts and keep-alives

See merge request !560
parents c7c183b7 cd374df0
No related branches found
No related tags found
1 merge request!560Properly configure connection timeouts and keep-alives
Pipeline #
......@@ -6,12 +6,10 @@ import (
"io/ioutil"
"net/http"
"path/filepath"
"time"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/docker/go-connections/sockets"
"github.com/docker/go-connections/tlsconfig"
"golang.org/x/net/context"
)
......@@ -112,7 +110,8 @@ func newHTTPTransport(c DockerCredentials) (*http.Transport, error) {
}
tr := &http.Transport{}
if err := sockets.ConfigureTransport(tr, proto, addr); err != nil {
if err := configureTransport(tr, proto, addr); err != nil {
return nil, err
}
......@@ -132,7 +131,6 @@ func newHTTPTransport(c DockerCredentials) (*http.Transport, error) {
return nil, err
}
tr.TLSHandshakeTimeout = 10 * time.Second
tr.TLSClientConfig = tlsConfig
}
......
package docker_helpers
import (
"net"
"net/http"
"time"
"github.com/docker/go-connections/sockets"
)
// Why 32? See https://github.com/docker/docker/pull/8035.
const defaultTimeout = 32 * time.Second
const defaultKeepAlive = 10 * time.Second
const defaultTLSHandshakeTimeout = 10 * time.Second
const defaultResponseHeaderTimeout = 30 * time.Second
const defaultExpectContinueTimeout = 30 * time.Second
const defaultIdleConnTimeout = time.Minute
// configureTransport configures the specified Transport according to the
// specified proto and addr.
// If the proto is unix (using a unix socket to communicate) or npipe the
// compression is disabled.
func configureTransport(tr *http.Transport, proto, addr string) error {
err := sockets.ConfigureTransport(tr, proto, addr)
if err != nil {
return err
}
tr.TLSHandshakeTimeout = defaultTLSHandshakeTimeout
tr.ResponseHeaderTimeout = defaultResponseHeaderTimeout
tr.ExpectContinueTimeout = defaultExpectContinueTimeout
tr.IdleConnTimeout = defaultIdleConnTimeout
// for network protocols set custom sockets with keep-alive
if proto == "tcp" || proto == "http" || proto == "https" {
dialer, err := sockets.DialerFromEnvironment(&net.Dialer{
Timeout: defaultTimeout,
KeepAlive: defaultKeepAlive,
})
if err != nil {
return err
}
tr.Dial = dialer.Dial
}
return nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment