From 3623b41a2e4f5edb17842e4c85ac995036a861e4 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Wed, 7 Aug 2019 16:50:50 +0200 Subject: [PATCH] Make RegisterNotificationListener() thread safe --- ha/ha.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ha/ha.go b/ha/ha.go index 20faf47b..68aa1a56 100644 --- a/ha/ha.go +++ b/ha/ha.go @@ -8,6 +8,7 @@ import ( "git.icinga.com/icingadb/icingadb-main/supervisor" "github.com/google/uuid" log "github.com/sirupsen/logrus" + "sync" "time" ) @@ -22,12 +23,14 @@ type HA struct { uid uuid.UUID super *supervisor.Supervisor notificationListeners []chan int + notificationListenersMutex sync.Mutex } func NewHA(super *supervisor.Supervisor) (*HA, error) { var err error ho := HA{ super: super, + notificationListenersMutex: sync.Mutex{}, } if ho.uid, err = uuid.NewRandom(); err != nil { @@ -190,7 +193,9 @@ func (h *HA) Run(chEnv chan *Environment) { func (h *HA) RegisterNotificationListener() chan int { ch := make(chan int) + h.notificationListenersMutex.Lock() h.notificationListeners = append(h.notificationListeners, ch) + h.notificationListenersMutex.Unlock() return ch }