Skip to content

Commit a4e25c3

Browse files
committed
net,internal/poll: skip TestAllocs when race is enabled on Windows
The Windows implementation of several network protocols make use of sync.Pool, which randomly drops cached items when race is enabled. While here, zero out the control buffer to allow it to be garbage collected. Fixes #75341 Change-Id: Ie20e21adef2edc02ca7b4a78012dd5f3a9f03bee Reviewed-on: https://go-review.googlesource.com/c/go/+/703195 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent dd82766 commit a4e25c3

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/internal/poll/fd_windows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ func freeWSAMsg(msg *windows.WSAMsg) {
196196
// Clear pointers to buffers so they can be released by garbage collector.
197197
msg.Buffers.Len = 0
198198
msg.Buffers.Buf = nil
199+
msg.Control.Len = 0
200+
msg.Control.Buf = nil
199201
wsaMsgPool.Put(msg)
200202
}
201203

src/net/udpsock_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"internal/asan"
11+
"internal/race"
1112
"internal/testenv"
1213
"net/netip"
1314
"os"
@@ -491,6 +492,12 @@ func TestAllocs(t *testing.T) {
491492
case "plan9", "js", "wasip1":
492493
// These implementations have not been optimized.
493494
t.Skipf("skipping on %v", runtime.GOOS)
495+
case "windows":
496+
if race.Enabled {
497+
// The Windows implementation make use of sync.Pool,
498+
// which randomly drops cached items when race is enabled.
499+
t.Skip("skipping test in race")
500+
}
494501
}
495502
if !testableNetwork("udp4") {
496503
t.Skipf("skipping: udp4 not available")

0 commit comments

Comments
 (0)