Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Client timeout fixes #12557

Merged
merged 5 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion api/client/webclient/webclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"os"
"strconv"
"strings"
"time"

"github.com/gravitational/teleport/api/client/proxy"
"github.com/gravitational/teleport/api/constants"
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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
}

Expand Down
11 changes: 9 additions & 2 deletions lib/utils/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down