From 3ad3d5931be1aa1fd1b59874eebb40e4b22e2206 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 17 Dec 2015 16:50:03 +0000 Subject: [PATCH] net: fix race in test Fixes race builders, broken in https://golang.org/cl/16953 Change-Id: Id61171672b69d0ca412de4b44bf2c598fe557906 Reviewed-on: https://go-review.googlesource.com/17936 Run-TryBot: Brad Fitzpatrick Reviewed-by: Russ Cox --- src/net/dnsclient_unix_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/net/dnsclient_unix_test.go b/src/net/dnsclient_unix_test.go index 95c14df52e..5ef02a1477 100644 --- a/src/net/dnsclient_unix_test.go +++ b/src/net/dnsclient_unix_test.go @@ -515,7 +515,8 @@ func BenchmarkGoLookupIPWithBrokenNameServer(b *testing.B) { type fakeDNSConn struct { // last query - q *dnsMsg + qmu sync.Mutex // guards q + q *dnsMsg // reply handler rh func(*dnsMsg) (*dnsMsg, error) } @@ -533,10 +534,15 @@ func (f *fakeDNSConn) SetDeadline(time.Time) error { } func (f *fakeDNSConn) writeDNSQuery(q *dnsMsg) error { + f.qmu.Lock() + defer f.qmu.Unlock() f.q = q return nil } func (f *fakeDNSConn) readDNSResponse() (*dnsMsg, error) { - return f.rh(f.q) + f.qmu.Lock() + q := f.q + f.qmu.Unlock() + return f.rh(q) }