From a9da6b73a828774850b88aa08430127c1a732b73 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 13 Jan 2022 13:01:29 -0800 Subject: [PATCH] net/dnscache: don't cancel the TLS context before writing to the result channel. Cancelling the context makes the timeout goroutine race with the write that reports a successful TLS handshake, so you can end up with a successful TLS handshake that mysteriously reports that it timed out after ~0s in flight. The context is always canceled and cleaned up as the function exits, which happens mere microseconds later, so just let function exit clean up and thereby avoid races. Signed-off-by: David Anderson --- net/dnscache/dnscache.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/net/dnscache/dnscache.go b/net/dnscache/dnscache.go index df17bc510..33375adc5 100644 --- a/net/dnscache/dnscache.go +++ b/net/dnscache/dnscache.go @@ -457,9 +457,7 @@ func TLSDialer(fwd DialContextFunc, dnsCache *Resolver, tlsConfigBase *tls.Confi } }() go func() { - err := tlsConn.Handshake() - handshakeTimeoutCancel() - errc <- err + errc <- tlsConn.Handshake() }() if err := <-errc; err != nil { tcpConn.Close()