From 8c4e4b72a8b54ef66d71de76461c719957bf51cc Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 8 Mar 2024 09:20:36 +0000 Subject: [PATCH] Notifier: pass parameters to goroutine explicitly Avoids possible false sharing between loops. Plausibly there is no problem in the current code, but it's easy enough to write it more safely. Signed-off-by: Bryan Boreham --- notifier/notifier.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/notifier/notifier.go b/notifier/notifier.go index 82c489a2e..d1832402f 100644 --- a/notifier/notifier.go +++ b/notifier/notifier.go @@ -539,9 +539,9 @@ func (n *Manager) sendAll(alerts ...*Alert) bool { ctx, cancel := context.WithTimeout(n.ctx, time.Duration(ams.cfg.Timeout)) defer cancel() - go func(client *http.Client, url string) { + go func(ctx context.Context, client *http.Client, url string, payload []byte, count int) { if err := n.sendOne(ctx, client, url, payload); err != nil { - level.Error(n.logger).Log("alertmanager", url, "count", len(amAlerts), "msg", "Error sending alert", "err", err) + level.Error(n.logger).Log("alertmanager", url, "count", count, "msg", "Error sending alert", "err", err) n.metrics.errors.WithLabelValues(url).Inc() } else { numSuccess.Inc() @@ -550,7 +550,7 @@ func (n *Manager) sendAll(alerts ...*Alert) bool { n.metrics.sent.WithLabelValues(url).Add(float64(len(amAlerts))) wg.Done() - }(ams.client, am.url().String()) + }(ctx, ams.client, am.url().String(), payload, len(amAlerts)) } ams.mtx.RUnlock()