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
This commit is contained in:
George K
2026-04-28 13:06:45 -07:00
committed by GitHub
parent dcb32165fa
commit 9538390107
+9 -7
View File
@@ -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