From 7bc9d453c2f7025c5fd254e95910bb4e2b6f4af6 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 14 Jun 2024 21:33:41 -0700 Subject: [PATCH] health: fix data race in new warnable code Fixes #12479 Change-Id: Ice84d5eb12d835eeddf6fc8cc337ea6b4dddcf6c Signed-off-by: Brad Fitzpatrick --- health/health.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/health/health.go b/health/health.go index db3bc8e90..957b43fa9 100644 --- a/health/health.go +++ b/health/health.go @@ -124,15 +124,8 @@ const ( var subsystemsWarnables = map[Subsystem]*Warnable{} -const legacyErrorArgKey = "LegacyError" - -// Warnable() returns a Warnable representing a legacy Subsystem. This is used -// *temporarily* while we migrate the old health infrastructure based on -// Subsystems to the new Warnables architecture. -func (s Subsystem) Warnable() *Warnable { - if w, ok := subsystemsWarnables[s]; ok { - return w - } else { +func init() { + for _, s := range []Subsystem{SysRouter, SysDNS, SysDNSOS, SysDNSManager, SysTKA} { w := Register(&Warnable{ Code: WarnableCode(s), Severity: SeverityMedium, @@ -141,10 +134,22 @@ func (s Subsystem) Warnable() *Warnable { }, }) subsystemsWarnables[s] = w - return w } } +const legacyErrorArgKey = "LegacyError" + +// Warnable returns a Warnable representing a legacy Subsystem. This is used +// temporarily (2024-06-14) while we migrate the old health infrastructure based +// on Subsystems to the new Warnables architecture. +func (s Subsystem) Warnable() *Warnable { + w, ok := subsystemsWarnables[s] + if !ok { + panic(fmt.Sprintf("health: no Warnable for Subsystem %q", s)) + } + return w +} + var registeredWarnables = map[WarnableCode]*Warnable{} // Register registers a new Warnable with the health package and returns it.