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 <bjboreham@gmail.com>
pull/13735/head
Bryan Boreham 9 months ago
parent 57c799132b
commit 8c4e4b72a8

@ -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()

Loading…
Cancel
Save