Browse code

cleaner handling of client socket access

In the go stdlib net/http Transport, the used connections are cached
when idled. This behaviour is intended for TCP connections and does not
behave correctly for unix sockets. Despite the
DefaultMaxIdleConnsPerHost being 2, the idled connections are held open
during a session. For large sessions like `docker rm $(docker ps -a -q)`
of thousands of containers, it will cause the client _and_ the server to
open too many fails and have failures.

Having keep alives not used for only unix sockets is a work around for
this stdlib issue.

Also this includes disabling compression when communicating over the
local unix socket too.

Signed-off-by: Vincent Batts <vbatts@redhat.com>

Vincent Batts authored on 2014/10/11 08:58:49
Showing 1 changed files
... ...
@@ -40,6 +40,14 @@ func (cli *DockerCli) HTTPClient() *http.Client {
40 40
 			return net.DialTimeout(cli.proto, cli.addr, 32*time.Second)
41 41
 		},
42 42
 	}
43
+	if cli.proto == "unix" {
44
+		// XXX workaround for net/http Transport which caches connections, but is
45
+		// intended for tcp connections, not unix sockets.
46
+		tr.DisableKeepAlives = true
47
+
48
+		// no need in compressing for local communications
49
+		tr.DisableCompression = true
50
+	}
43 51
 	return &http.Client{Transport: tr}
44 52
 }
45 53