mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-17 03:45:13 +00:00
Merge pull request #762 from mopemope/fix-fd-leak
Fix Docker Client FileDescriptor Leak
This commit is contained in:
commit
f1c5a45b5a
2 changed files with 14 additions and 0 deletions
|
@ -270,6 +270,8 @@ func (b *Builder) setup() error {
|
||||||
// and the supporting service containers.
|
// and the supporting service containers.
|
||||||
func (b *Builder) teardown() error {
|
func (b *Builder) teardown() error {
|
||||||
|
|
||||||
|
defer b.dockerClient.CloseIdleConnections()
|
||||||
|
|
||||||
// stop and destroy the container
|
// stop and destroy the container
|
||||||
if b.container != nil {
|
if b.container != nil {
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,11 @@ func NewHostCert(uri string, cert, key []byte) (*Client, error) {
|
||||||
// if no certificate is provided returns the
|
// if no certificate is provided returns the
|
||||||
// client with no TLS configured.
|
// client with no TLS configured.
|
||||||
if cert == nil || key == nil || len(cert) == 0 || len(key) == 0 {
|
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
|
return cli, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,6 +368,7 @@ func (c *Client) HTTPClient() *http.Client {
|
||||||
return &http.Client{Transport: c.trans}
|
return &http.Client{Transport: c.trans}
|
||||||
}
|
}
|
||||||
return &http.Client{
|
return &http.Client{
|
||||||
|
// WARN Leak Transport's Pooling Connection
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
Dial: func(dial_network, dial_addr string) (net.Conn, error) {
|
Dial: func(dial_network, dial_addr string) (net.Conn, error) {
|
||||||
return net.DialTimeout(c.proto, c.addr, 32*time.Second)
|
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)
|
return net.Dial(c.proto, c.addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) CloseIdleConnections() {
|
||||||
|
if c.trans != nil {
|
||||||
|
c.trans.CloseIdleConnections()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue