net: fix data race in benchmarks
Fixes #10307.
Change-Id: If70f36a6f1c4e465a47a0bc4d38b318424111106
Reviewed-on: https://go-review.googlesource.com/8330
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/src/net/tcp_test.go b/src/net/tcp_test.go
index 434c9c6..e33e5f2 100644
--- a/src/net/tcp_test.go
+++ b/src/net/tcp_test.go
@@ -59,8 +59,7 @@
}
func benchmarkTCP(b *testing.B, persistent, timeout bool, laddr string) {
- uninstallTestHooks()
- defer installTestHooks()
+ testHookUninstaller.Do(func() { uninstallTestHooks() })
const msgLen = 512
conns := b.N
@@ -170,13 +169,13 @@
}
func benchmarkTCPConcurrentReadWrite(b *testing.B, laddr string) {
+ testHookUninstaller.Do(func() { uninstallTestHooks() })
+
// The benchmark creates GOMAXPROCS client/server pairs.
// Each pair creates 4 goroutines: client reader/writer and server reader/writer.
// The benchmark stresses concurrent reading and writing to the same connection.
// Such pattern is used in net/http and net/rpc.
- uninstallTestHooks()
- defer installTestHooks()
b.StopTimer()
P := runtime.GOMAXPROCS(0)