mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-27 02:37:38 +00:00
net/dnscache: use tls.Conn.HandshakeContext.
Go 1.17 added a HandshakeContext func to take care of timeouts during TLS handshaking, so switch from our homegrown goroutine implementation to the standard way. Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
a9da6b73a8
commit
463b3e8f62
@ -444,22 +444,9 @@ func TLSDialer(fwd DialContextFunc, dnsCache *Resolver, tlsConfigBase *tls.Confi
|
|||||||
}
|
}
|
||||||
tlsConn := tls.Client(tcpConn, cfg)
|
tlsConn := tls.Client(tcpConn, cfg)
|
||||||
|
|
||||||
errc := make(chan error, 2)
|
|
||||||
handshakeCtx, handshakeTimeoutCancel := context.WithTimeout(ctx, 5*time.Second)
|
handshakeCtx, handshakeTimeoutCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||||
defer handshakeTimeoutCancel()
|
defer handshakeTimeoutCancel()
|
||||||
done := make(chan bool)
|
if err := tlsConn.HandshakeContext(handshakeCtx); err != nil {
|
||||||
defer close(done)
|
|
||||||
go func() {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-handshakeCtx.Done():
|
|
||||||
errc <- errTLSHandshakeTimeout
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
go func() {
|
|
||||||
errc <- tlsConn.Handshake()
|
|
||||||
}()
|
|
||||||
if err := <-errc; err != nil {
|
|
||||||
tcpConn.Close()
|
tcpConn.Close()
|
||||||
// TODO: if err != errTLSHandshakeTimeout,
|
// TODO: if err != errTLSHandshakeTimeout,
|
||||||
// assume it might be some captive portal or
|
// assume it might be some captive portal or
|
||||||
|
Loading…
x
Reference in New Issue
Block a user