Add timeout to auth http requests (#13976)

Sets the `Timeout` of the http.Client  used by the auth client
to 30s to prevent requests from blocking indefinitely. There
have been several failure scenarios that result in teleport being
completely stuck due to never receiving a response from an
http request. The 30s upper bound should prevent this, while
also being long enough that it shouldn't impact any requests
which may be slow.
This commit is contained in:
rosstimothy 2022-07-05 08:50:24 -04:00 committed by GitHub
parent 3c2decdca7
commit 0e937edd4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -193,7 +193,10 @@ func NewHTTPClient(cfg client.Config, tls *tls.Config, params ...roundtrip.Clien
clientParams := append(
[]roundtrip.ClientParam{
roundtrip.HTTPClient(&http.Client{Transport: otelhttp.NewTransport(breaker.NewRoundTripper(cb, transport))}),
roundtrip.HTTPClient(&http.Client{
Timeout: defaults.HTTPRequestTimeout,
Transport: otelhttp.NewTransport(breaker.NewRoundTripper(cb, transport)),
}),
roundtrip.SanitizerEnabled(true),
},
params...,

View file

@ -112,6 +112,9 @@ const (
// HTTPIdleTimeout is a default timeout for idle HTTP connections
HTTPIdleTimeout = 30 * time.Second
// HTTPRequestTimeout is a default timeout for HTTP requests
HTTPRequestTimeout = 30 * time.Second
// WebHeadersTimeout is a timeout that is set for web requests
// before browsers raise "Timeout waiting web headers" error in
// the browser