Skip to content

Commit

Permalink
use higher level http.Client interface for timeouts, bump default tim…
Browse files Browse the repository at this point in the history
…eout way up for better resiliency to slow requests
  • Loading branch information
danenania committed Oct 9, 2018
1 parent 2f253a3 commit 7b8632a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ func init() {
RootCmd.Flags().StringVar(&clientVersion, "client-version", "", "calling client library version (default is none)")
RootCmd.Flags().BoolVarP(&printVersion, "version", "v", false, "prints the version")
RootCmd.Flags().BoolVar(&verboseOutput, "verbose", false, "print verbose output (default is false)")
RootCmd.Flags().Float64Var(&timeoutSeconds, "timeout", 2.0, "timeout in seconds for http requests")
RootCmd.Flags().Float64Var(&timeoutSeconds, "timeout", 10.0, "timeout in seconds for http requests")
}
16 changes: 1 addition & 15 deletions fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -138,21 +137,8 @@ func UrlWithLoggingParams(baseUrl string, options FetchOptions) string {
}

func InitHttpClient(timeoutSeconds float64) {
// http.Client.Get reuses the transport. this should be created once.
tp := http.Transport{}
to := time.Second * time.Duration(timeoutSeconds)

tp.DialContext = (&net.Dialer{
Timeout: to,
}).DialContext

tp.TLSHandshakeTimeout = to
tp.ResponseHeaderTimeout = to
tp.ExpectContinueTimeout = to

Client = &http.Client{
Transport: &tp,
}
Client = &http.Client{Timeout: to}
}

func httpExecRequest(
Expand Down

0 comments on commit 7b8632a

Please sign in to comment.