]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/tls: retry net.Dial flakes on Dragonfly
authorBryan C. Mills <bcmills@google.com>
Mon, 21 Oct 2019 18:12:26 +0000 (14:12 -0400)
committerBryan C. Mills <bcmills@google.com>
Mon, 21 Oct 2019 19:06:29 +0000 (19:06 +0000)
localPipe currently flakes in various crypto/tls tests. Since that
function doesn't seem to flake anywhere else, I suspect a kernel bug.

To make the test less flaky, retry the Dial if we suspect that it is
affected. (Worst case, we delay the test by a few seconds before
erroring out as usual.)

Fixes #29583

Change-Id: I357990ffa316edb471bd7d46d6404fa0884da646
Reviewed-on: https://go-review.googlesource.com/c/go/+/202557
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/crypto/tls/handshake_test.go
src/crypto/tls/handshake_unix_test.go [new file with mode: 0644]

index 6081ab20f03466f4861cddf4c42ba078601f71b2..01c234e60624cc62bb46cf9cf6cff92c77952dc8 100644 (file)
@@ -17,6 +17,7 @@ import (
        "net"
        "os"
        "os/exec"
+       "runtime"
        "strconv"
        "strings"
        "sync"
@@ -243,19 +244,29 @@ func localServer(l net.Listener) {
        }
 }
 
+var isConnRefused = func(err error) bool { return false }
+
 func localPipe(t testing.TB) (net.Conn, net.Conn) {
        localListener.mu.Lock()
        defer localListener.mu.Unlock()
 
        addr := localListener.addr
 
+       var err error
 Dialing:
        // We expect a rare mismatch, but probably not 5 in a row.
        for i := 0; i < 5; i++ {
                tooSlow := time.NewTimer(1 * time.Second)
                defer tooSlow.Stop()
-               c1, err := net.Dial(addr.Network(), addr.String())
+               var c1 net.Conn
+               c1, err = net.Dial(addr.Network(), addr.String())
                if err != nil {
+                       if runtime.GOOS == "dragonfly" && isConnRefused(err) {
+                               // golang.org/issue/29583: Dragonfly sometimes returned a spurious
+                               // ECONNREFUSED.
+                               <-tooSlow.C
+                               continue
+                       }
                        t.Fatalf("localPipe: %v", err)
                }
                if localFlakes == 2 && i == 0 {
@@ -279,7 +290,7 @@ Dialing:
                }
        }
 
-       t.Fatalf("localPipe: failed to connect")
+       t.Fatalf("localPipe: failed to connect: %v", err)
        panic("unreachable")
 }
 
diff --git a/src/crypto/tls/handshake_unix_test.go b/src/crypto/tls/handshake_unix_test.go
new file mode 100644 (file)
index 0000000..7271854
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
+
+package tls
+
+import (
+       "errors"
+       "syscall"
+)
+
+func init() {
+       isConnRefused = func(err error) bool {
+               return errors.Is(err, syscall.ECONNREFUSED)
+       }
+}