From 463b3e8f62e86055c520d17643c2347240ebf68e Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 13 Jan 2022 13:01:29 -0800 Subject: [PATCH] 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 --- net/dnscache/dnscache.go | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/net/dnscache/dnscache.go b/net/dnscache/dnscache.go index 33375adc5..2f96aab24 100644 --- a/net/dnscache/dnscache.go +++ b/net/dnscache/dnscache.go @@ -444,22 +444,9 @@ func TLSDialer(fwd DialContextFunc, dnsCache *Resolver, tlsConfigBase *tls.Confi } tlsConn := tls.Client(tcpConn, cfg) - errc := make(chan error, 2) handshakeCtx, handshakeTimeoutCancel := context.WithTimeout(ctx, 5*time.Second) defer handshakeTimeoutCancel() - done := make(chan bool) - defer close(done) - go func() { - select { - case <-done: - case <-handshakeCtx.Done(): - errc <- errTLSHandshakeTimeout - } - }() - go func() { - errc <- tlsConn.Handshake() - }() - if err := <-errc; err != nil { + if err := tlsConn.HandshakeContext(handshakeCtx); err != nil { tcpConn.Close() // TODO: if err != errTLSHandshakeTimeout, // assume it might be some captive portal or