mirror of
https://github.com/gravitational/teleport
synced 2024-10-19 16:53:57 +00:00
Client timeout fixes (#12557)
* Respect timeout in `(directDial).DialTimeout` * Add a Timeout to the api/client/webclient calls * Respect timeout in (proxyDial).DialTimeout * Applied suggestion Co-authored-by: Alan Parra <alan.parra@goteleport.com> Co-authored-by: Alan Parra <alan.parra@goteleport.com>
This commit is contained in:
parent
80bdb11c89
commit
3de0f5dfda
|
@ -30,6 +30,7 @@ import (
|
|||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gravitational/teleport/api/client/proxy"
|
||||
"github.com/gravitational/teleport/api/constants"
|
||||
|
@ -61,6 +62,8 @@ type Config struct {
|
|||
ExtraHeaders map[string]string
|
||||
// IgnoreHTTPProxy disables support for HTTP proxying when true.
|
||||
IgnoreHTTPProxy bool
|
||||
// Timeout is a timeout for requests.
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
// CheckAndSetDefaults checks and sets defaults
|
||||
|
@ -72,7 +75,9 @@ func (c *Config) CheckAndSetDefaults() error {
|
|||
if c.ProxyAddr == "" && os.Getenv(defaults.TunnelPublicAddrEnvar) == "" {
|
||||
return trace.BadParameter(message, "missing parameter ProxyAddr")
|
||||
}
|
||||
|
||||
if c.Timeout == 0 {
|
||||
c.Timeout = defaults.DefaultDialTimeout
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -94,6 +99,7 @@ func newWebClient(cfg *Config) (*http.Client, error) {
|
|||
}
|
||||
return &http.Client{
|
||||
Transport: otelhttp.NewTransport(proxy.NewHTTPFallbackRoundTripper(&transport, cfg.Insecure)),
|
||||
Timeout: cfg.Timeout,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,9 @@ func (d directDial) DialTimeout(network, address string, timeout time.Duration)
|
|||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
tlsConn, err := tls.Dial("tcp", address, conf)
|
||||
tlsConn, err := tls.DialWithDialer(&net.Dialer{
|
||||
Timeout: timeout,
|
||||
}, "tcp", address, conf)
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
|
@ -184,7 +186,12 @@ func (d proxyDial) DialTimeout(network, address string, timeout time.Duration) (
|
|||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
conn = tls.Client(conn, conf)
|
||||
tlsConn := tls.Client(conn, conf)
|
||||
if err = tlsConn.HandshakeContext(ctx); err != nil {
|
||||
conn.Close()
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
conn = tlsConn
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue