diff --git a/shared/build/build.go b/shared/build/build.go index d85ff2a1..2226cc4f 100644 --- a/shared/build/build.go +++ b/shared/build/build.go @@ -270,6 +270,8 @@ func (b *Builder) setup() error { // and the supporting service containers. func (b *Builder) teardown() error { + defer b.dockerClient.CloseIdleConnections() + // stop and destroy the container if b.container != nil { diff --git a/shared/build/docker/client.go b/shared/build/docker/client.go index 8961598a..678059b9 100644 --- a/shared/build/docker/client.go +++ b/shared/build/docker/client.go @@ -71,6 +71,11 @@ func NewHostCert(uri string, cert, key []byte) (*Client, error) { // if no certificate is provided returns the // client with no TLS configured. if cert == nil || key == nil || len(cert) == 0 || len(key) == 0 { + cli.trans = &http.Transport{ + Dial: func(dial_network, dial_addr string) (net.Conn, error) { + return net.DialTimeout(cli.proto, cli.addr, 32*time.Second) + }, + } return cli, nil } @@ -363,6 +368,7 @@ func (c *Client) HTTPClient() *http.Client { return &http.Client{Transport: c.trans} } return &http.Client{ + // WARN Leak Transport's Pooling Connection Transport: &http.Transport{ Dial: func(dial_network, dial_addr string) (net.Conn, error) { return net.DialTimeout(c.proto, c.addr, 32*time.Second) @@ -377,3 +383,9 @@ func (c *Client) Dial() (net.Conn, error) { } return net.Dial(c.proto, c.addr) } + +func (c *Client) CloseIdleConnections() { + if c.trans != nil { + c.trans.CloseIdleConnections() + } +}