Skip to content

Commit

Permalink
Fix file-descriptor leak
Browse files Browse the repository at this point in the history
Clone client transport from http.DefaultTransport
instead of creating a zeroed transport struct.

With an empty timeout-struct all timeout-values are zeroed disabling some timeouts and TTLs.

See https://golang.org/src/net/http/transpor.go#L194 and following.
  • Loading branch information
IljaN committed Jul 8, 2020
1 parent 1627360 commit 99e82fc
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkg/rhttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (
"io"
"net/http"

"go.opencensus.io/plugin/ochttp"

"github.com/cs3org/reva/pkg/token"
"github.com/pkg/errors"
"go.opencensus.io/plugin/ochttp"
)

// GetHTTPClient returns an http client with open census tracing support.
Expand All @@ -35,17 +36,19 @@ import (
func GetHTTPClient(opts ...Option) *http.Client {
options := newOptions(opts...)

tr := http.DefaultTransport.(*http.Transport).Clone()
tr.DisableKeepAlives = options.DisableKeepAlive
tr.TLSClientConfig = &tls.Config{
InsecureSkipVerify: options.Insecure,
}

httpClient := &http.Client{
Timeout: options.Timeout,
Transport: &ochttp.Transport{
Base: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: options.Insecure,
},
DisableKeepAlives: options.DisableKeepAlive,
},
Base: tr,
},
}

return httpClient
}

Expand Down

0 comments on commit 99e82fc

Please sign in to comment.