Commit 71d127aa authored by Bryan C. Mills's avatar Bryan C. Mills

crypto/tls: retry net.Dial flakes on Dragonfly

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent ba97d0d8
...@@ -17,6 +17,7 @@ import ( ...@@ -17,6 +17,7 @@ import (
"net" "net"
"os" "os"
"os/exec" "os/exec"
"runtime"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
...@@ -243,19 +244,29 @@ func localServer(l net.Listener) { ...@@ -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) { func localPipe(t testing.TB) (net.Conn, net.Conn) {
localListener.mu.Lock() localListener.mu.Lock()
defer localListener.mu.Unlock() defer localListener.mu.Unlock()
addr := localListener.addr addr := localListener.addr
var err error
Dialing: Dialing:
// We expect a rare mismatch, but probably not 5 in a row. // We expect a rare mismatch, but probably not 5 in a row.
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
tooSlow := time.NewTimer(1 * time.Second) tooSlow := time.NewTimer(1 * time.Second)
defer tooSlow.Stop() 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 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) t.Fatalf("localPipe: %v", err)
} }
if localFlakes == 2 && i == 0 { if localFlakes == 2 && i == 0 {
...@@ -279,7 +290,7 @@ Dialing: ...@@ -279,7 +290,7 @@ Dialing:
} }
} }
t.Fatalf("localPipe: failed to connect") t.Fatalf("localPipe: failed to connect: %v", err)
panic("unreachable") panic("unreachable")
} }
......
// 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)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment