Skip to content

Commit

Permalink
net: avoid darwin/arm64 platform bug in TestCloseWrite
Browse files Browse the repository at this point in the history
On darwin_arm64, reading from a socket at the same time as the other
end is closing it will occasionally hang for 60 seconds before
returning ECONNRESET. (This is a macOS issue, not a Go issue.)

Work around this condition by adding a brief sleep before the read.

Fixes #49352 (we hope).
Updates #37795.

Change-Id: I4052aec21d311d7370550aea9dd7941f39141133
Reviewed-on: https://go-review.googlesource.com/c/go/+/414534
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed Jun 27, 2022
1 parent 68289f3 commit a42573c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/net/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ func TestCloseWrite(t *testing.T) {
t.Error(err)
return
}

// Workaround for https://go.dev/issue/49352.
// On arm64 macOS (current as of macOS 12.4),
// reading from a socket at the same time as the client
// is closing it occasionally hangs for 60 seconds before
// returning ECONNRESET. Sleep for a bit to give the
// socket time to close before trying to read from it.
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
time.Sleep(10 * time.Millisecond)
}

if !deadline.IsZero() {
c.SetDeadline(deadline)
}
Expand Down

0 comments on commit a42573c

Please sign in to comment.