From ccf0e6b0dc5eb300fe2d8b7c156a992dd32f8bf5 Mon Sep 17 00:00:00 2001 From: Gary Hansen Date: Tue, 7 Jul 2026 22:08:06 +1000 Subject: [PATCH] fix: data race on test DNS handler flag under -race TestClientAgainstLocalServer captured RecursionDesired into a plain bool from the miekg server handler goroutine and read it from the test goroutine; the UDP round-trip gives no happens-before edge, so CI's -race run flagged it. Use atomic.Bool. Co-Authored-By: Claude Fable 5 --- internal/dns/real_exchange_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/dns/real_exchange_test.go b/internal/dns/real_exchange_test.go index 2a772e1..677f0ad 100644 --- a/internal/dns/real_exchange_test.go +++ b/internal/dns/real_exchange_test.go @@ -3,6 +3,7 @@ package dns import ( "context" "net" + "sync/atomic" "testing" "time" @@ -107,9 +108,11 @@ func TestRealExchangeUnreachable(t *testing.T) { } func TestClientAgainstLocalServer(t *testing.T) { - var sawRD bool + // Written by the server handler goroutine, read by the test goroutine; + // the UDP round-trip provides no happens-before edge, so use an atomic. + var sawRD atomic.Bool addr := startTestDNSServer(t, "udp", func(w dns.ResponseWriter, r *dns.Msg) { - sawRD = r.RecursionDesired + sawRD.Store(r.RecursionDesired) aHandler("5.6.7.8")(w, r) }) @@ -127,7 +130,7 @@ func TestClientAgainstLocalServer(t *testing.T) { if len(resp.Answer) == 0 { t.Fatal("expected answers") } - if sawRD { + if sawRD.Load() { t.Error("wire query must have RD=0") } }