Skip to content

Commit 3ad3d59

Browse files
committed
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 <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent 0d641c7 commit 3ad3d59

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/net/dnsclient_unix_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ func BenchmarkGoLookupIPWithBrokenNameServer(b *testing.B) {
515515

516516
type fakeDNSConn struct {
517517
// last query
518-
q *dnsMsg
518+
qmu sync.Mutex // guards q
519+
q *dnsMsg
519520
// reply handler
520521
rh func(*dnsMsg) (*dnsMsg, error)
521522
}
@@ -533,10 +534,15 @@ func (f *fakeDNSConn) SetDeadline(time.Time) error {
533534
}
534535

535536
func (f *fakeDNSConn) writeDNSQuery(q *dnsMsg) error {
537+
f.qmu.Lock()
538+
defer f.qmu.Unlock()
536539
f.q = q
537540
return nil
538541
}
539542

540543
func (f *fakeDNSConn) readDNSResponse() (*dnsMsg, error) {
541-
return f.rh(f.q)
544+
f.qmu.Lock()
545+
q := f.q
546+
f.qmu.Unlock()
547+
return f.rh(q)
542548
}

0 commit comments

Comments
 (0)