1
0
mirror of https://github.com/golang/go synced 2024-09-29 22:14:29 -06:00

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: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Bryan C. Mills 2019-10-21 14:12:26 -04:00
parent ba97d0d84d
commit 71d127aafd
2 changed files with 31 additions and 2 deletions

View 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")
}

View File

@ -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)
}
}