Skip to content

Commit

Permalink
Fix: CPU hot busyloop by setting a default timeout to 30s, if not set (
Browse files Browse the repository at this point in the history
…#1259)

* Fix: CPU hot busyloop by setting a default timeout to 30s, if not set

Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>

* as commented

Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
  • Loading branch information
szuecs committed Dec 19, 2019
1 parent 2f65a30 commit 592f6d8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion net/httpclient.go
Expand Up @@ -10,6 +10,10 @@ import (
"github.com/opentracing/opentracing-go/ext"
)

const (
defaultIdleConnTimeout = 30 * time.Second
)

// Options are mostly passed to the http.Transport of the same
// name. Options.Timeout can be used as default for all timeouts, that
// are not set. You can pass an opentracing.Tracer
Expand Down Expand Up @@ -85,7 +89,11 @@ func NewTransport(options Options) *Transport {
options.TLSHandshakeTimeout = options.Timeout
}
if options.IdleConnTimeout == 0 {
options.IdleConnTimeout = options.Timeout
if options.Timeout != 0 {
options.IdleConnTimeout = options.Timeout
} else {
options.IdleConnTimeout = defaultIdleConnTimeout
}
}
if options.ResponseHeaderTimeout == 0 {
options.ResponseHeaderTimeout = options.Timeout
Expand Down

0 comments on commit 592f6d8

Please sign in to comment.