1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-24 08:02:18 +02:00

Fix Docker Client FileDescriptor Leak

This commit is contained in:
mopemoepe 2014-12-19 01:58:17 +09:00
parent 0452090358
commit 2059c6f4e6
2 changed files with 14 additions and 0 deletions

View File

@ -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 {

View File

@ -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()
}
}