Skip to content

Commit 3bcbab3

Browse files
author
Bryan C. Mills
committed
ipv4: retry ENOBUFS errors in TestPacketConnConcurrentReadWriteUnicast
This change is sheer speculation based on the failures observed in golang/go#37319. (A deadlock in the test prevented us from seeing the actual failure mode of golang/go#51342 up until CL 387915, and it isn't obvious to me that we should wait for another failure before trying a likely — and otherwise harmless — fix.) This is a port of CL 376095 to the "ipv4" package. Fixes golang/go#51342. (Maybe.) Change-Id: Idd6d2d785dbb0c98404f99bd98a3c4ddc11cb2cf Reviewed-on: https://go-review.googlesource.com/c/net/+/387916 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 f80d34d commit 3bcbab3

File tree

3 files changed

+70
-15
lines changed

3 files changed

+70
-15
lines changed

ipv4/errors_other_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2022 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 ipv4_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+
}

ipv4/errors_unix_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2022 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 ipv4_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+
}

ipv4/readwrite_test.go

+36-15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313
"sync"
1414
"testing"
15+
"time"
1516

1617
"golang.org/x/net/internal/iana"
1718
"golang.org/x/net/ipv4"
@@ -450,12 +451,22 @@ func testPacketConnConcurrentReadWriteUnicast(t *testing.T, p *ipv4.PacketConn,
450451
if err := p.SetControlMessage(cf, toggle); err != nil {
451452
fatalf("%v", err)
452453
}
453-
n, err := p.WriteTo(data, &cm, dst)
454-
if err != nil {
455-
fatalf("%v", err)
456-
}
457-
if n != len(data) {
458-
fatalf("got %d; want %d", n, len(data))
454+
455+
backoff := time.Millisecond
456+
for {
457+
n, err := p.WriteTo(data, &cm, dst)
458+
if err != nil {
459+
if n == 0 && isENOBUFS(err) {
460+
time.Sleep(backoff)
461+
backoff *= 2
462+
continue
463+
}
464+
fatalf("%v", err)
465+
}
466+
if n != len(data) {
467+
fatalf("got %d; want %d", n, len(data))
468+
}
469+
break
459470
}
460471
}
461472
batchWriter := func(toggle bool) {
@@ -476,15 +487,25 @@ func testPacketConnConcurrentReadWriteUnicast(t *testing.T, p *ipv4.PacketConn,
476487
Addr: dst,
477488
},
478489
}
479-
n, err := p.WriteBatch(ms, 0)
480-
if err != nil {
481-
fatalf("%v", err)
482-
}
483-
if n != len(ms) {
484-
fatalf("got %d; want %d", n, len(ms))
485-
}
486-
if ms[0].N != len(data) {
487-
fatalf("got %d; want %d", ms[0].N, len(data))
490+
491+
backoff := time.Millisecond
492+
for {
493+
n, err := p.WriteBatch(ms, 0)
494+
if err != nil {
495+
if n == 0 && isENOBUFS(err) {
496+
time.Sleep(backoff)
497+
backoff *= 2
498+
continue
499+
}
500+
fatalf("%v", err)
501+
}
502+
if n != len(ms) {
503+
fatalf("got %d; want %d", n, len(ms))
504+
}
505+
if ms[0].N != len(data) {
506+
fatalf("got %d; want %d", ms[0].N, len(data))
507+
}
508+
break
488509
}
489510
}
490511

0 commit comments

Comments
 (0)