diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 24af96e49..98508a188 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -157,7 +157,7 @@ }, { "ImportPath": "github.com/hashicorp/go-cleanhttp", - "Rev": "5df5ddc69534f1a4697289f1dca2193fbb40213f" + "Rev": "ce617e79981a8fff618bb643d155133a8f38db96" }, { "ImportPath": "github.com/hashicorp/go-multierror", diff --git a/Godeps/_workspace/src/github.com/hashicorp/go-cleanhttp/cleanhttp.go b/Godeps/_workspace/src/github.com/hashicorp/go-cleanhttp/cleanhttp.go index 1676d79cb..c692e23f4 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/go-cleanhttp/cleanhttp.go +++ b/Godeps/_workspace/src/github.com/hashicorp/go-cleanhttp/cleanhttp.go @@ -3,13 +3,14 @@ package cleanhttp import ( "net" "net/http" + "runtime" "time" ) // DefaultTransport returns a new http.Transport with the same default values // as http.DefaultTransport func DefaultTransport() *http.Transport { - return &http.Transport{ + transport := &http.Transport{ Proxy: http.ProxyFromEnvironment, Dial: (&net.Dialer{ Timeout: 30 * time.Second, @@ -17,6 +18,8 @@ func DefaultTransport() *http.Transport { }).Dial, TLSHandshakeTimeout: 10 * time.Second, } + SetTransportFinalizer(transport) + return transport } // DefaultClient returns a new http.Client with the same default values as @@ -26,3 +29,12 @@ func DefaultClient() *http.Client { Transport: DefaultTransport(), } } + +// SetTransportFinalizer sets a finalizer on the transport to ensure that +// idle connections are closed prior to garbage collection; otherwise +// these may leak +func SetTransportFinalizer(transport *http.Transport) { + runtime.SetFinalizer(&transport, func(t **http.Transport) { + (*t).CloseIdleConnections() + }) +}