Jelajahi Sumber

fix(alerting): scope variable was updated

closes #6228
bergquist 9 tahun lalu
induk
melakukan
c0829903ba
1 mengubah file dengan 3 tambahan dan 2 penghapusan
  1. 3 2
      pkg/services/alerting/notifier.go

+ 3 - 2
pkg/services/alerting/notifier.go

@@ -68,8 +68,9 @@ func (n *RootNotifier) sendNotifications(context *EvalContext, notifiers []Notif
 	g, _ := errgroup.WithContext(context.Ctx)
 
 	for _, notifier := range notifiers {
-		n.log.Info("Sending notification", "type", notifier.GetType(), "id", notifier.GetNotifierId(), "isDefault", notifier.GetIsDefault())
-		g.Go(func() error { return notifier.Notify(context) })
+		not := notifier //avoid updating scope variable in go routine
+		n.log.Info("Sending notification", "type", not.GetType(), "id", not.GetNotifierId(), "isDefault", not.GetIsDefault())
+		g.Go(func() error { return not.Notify(context) })
 	}
 
 	return g.Wait()