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 54cfec2
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pkg/rhttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ package rhttp
import (
"context"
"crypto/tls"
"go.opencensus.io/plugin/ochttp"
"io"
"net/http"

"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 +35,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 54cfec2

Please sign in to comment.