Skip to content

Commit

Permalink
Notifier: pass parameters to goroutine explicitly
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bboreham committed Mar 8, 2024
1 parent 57c7991 commit 8c4e4b7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions notifier/notifier.go
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 8c4e4b7

Please sign in to comment.