From 9538390107d93e6f8294918c89e2cf5889b1552f Mon Sep 17 00:00:00 2001 From: George K Date: Tue, 28 Apr 2026 13:06:45 -0700 Subject: [PATCH] fix(coderd/healthcheck/derphealth): avoid data races in DERP report (#24795) Fixes two data races, one introduced in #24544 and one pre-existing. Related to: https://github.com/coder/internal/issues/1505 --- coderd/healthcheck/derphealth/derp.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/coderd/healthcheck/derphealth/derp.go b/coderd/healthcheck/derphealth/derp.go index c85bff5776..cdaea4ed3c 100644 --- a/coderd/healthcheck/derphealth/derp.go +++ b/coderd/healthcheck/derphealth/derp.go @@ -113,13 +113,6 @@ func (r *Report) Run(ctx context.Context, opts *ReportOptions) { mu.Unlock() }() } - if !hasDERP { - r.Severity = health.SeverityWarning - r.Warnings = append(r.Warnings, health.Messagef( - health.CodeDERPNoNodes, noDERP, - )) - } - ncLogf := func(format string, args ...interface{}) { mu.Lock() r.NetcheckLogs = append(r.NetcheckLogs, fmt.Sprintf(format, args...)) @@ -134,11 +127,20 @@ func (r *Report) Run(ctx context.Context, opts *ReportOptions) { r.Netcheck = ncReport r.NetcheckErr = convertError(netcheckErr) if mapVaryDest, _ := r.Netcheck.MappingVariesByDestIP.Get(); mapVaryDest { + mu.Lock() r.Warnings = append(r.Warnings, health.Messagef(health.CodeSTUNMapVaryDest, stunMapVaryDest)) + mu.Unlock() } wg.Wait() + if !hasDERP { + r.Severity = health.SeverityWarning + r.Warnings = append(r.Warnings, health.Messagef( + health.CodeDERPNoNodes, noDERP, + )) + } + // Count the number of STUN-capable nodes. var stunCapableNodes int var stunTotalNodes int