Skip to content

Commit eba003a

Browse files
author
Bryan C. Mills
committed
ipv6: in PacketConn tests, retry writes that fail with ENOBUFS
In golang/go#37319, TestPacketConnReadWriteMulticastUDP was observed to occasionally fail with ENOBUFS on macOS. This change adds a retry loop for that test function. There are some other related test functions that may also wrap sendmsg, but I have not observed any ENOBUFS failures for them — I suspect that some difference in protocol or traffic class prevents this failure mode, but we can always add more retry loops if we discover that they are actually needed. Fixes golang/go#37319. Change-Id: I99fce94ff10c6f3c09d493712eba782ec8707a58 Reviewed-on: https://go-review.googlesource.com/c/net/+/369742 Trust: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 266e24b commit eba003a

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

ipv6/errors_other_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build !(aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris)
6+
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris
7+
8+
package ipv6_test
9+
10+
// isENOBUFS reports whether err is unix.ENOBUFS.
11+
// (Always false on non-Unix platforms.)
12+
func isENOBUFS(err error) bool {
13+
return false
14+
}

ipv6/errors_unix_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
6+
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
7+
8+
package ipv6_test
9+
10+
import (
11+
"errors"
12+
13+
"golang.org/x/sys/unix"
14+
)
15+
16+
// isENOBUFS reports whether err is unix.ENOBUFS.
17+
// (Always false on non-Unix platforms.)
18+
func isENOBUFS(err error) bool {
19+
return errors.Is(err, unix.ENOBUFS)
20+
}

ipv6/multicast_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"runtime"
1212
"testing"
13+
"time"
1314

1415
"golang.org/x/net/icmp"
1516
"golang.org/x/net/internal/iana"
@@ -100,11 +101,24 @@ func TestPacketConnReadWriteMulticastUDP(t *testing.T) {
100101
t.Fatal(err)
101102
}
102103
cm.HopLimit = i + 1
103-
if n, err := p.WriteTo(wb, &cm, &grp); err != nil {
104-
t.Fatal(err)
105-
} else if n != len(wb) {
106-
t.Fatal(err)
104+
105+
backoff := time.Millisecond
106+
for {
107+
n, err := p.WriteTo(wb, &cm, &grp)
108+
if err != nil {
109+
if n == 0 && isENOBUFS(err) {
110+
time.Sleep(backoff)
111+
backoff *= 2
112+
continue
113+
}
114+
t.Fatal(err)
115+
}
116+
if n != len(wb) {
117+
t.Fatalf("wrote %v bytes; want %v", n, len(wb))
118+
}
119+
break
107120
}
121+
108122
rb := make([]byte, 128)
109123
if n, _, _, err := p.ReadFrom(rb); err != nil {
110124
t.Fatal(err)

0 commit comments

Comments
 (0)