From bdfac4ff53f3dcaa76ec98b7621d15a9c88ddd88 Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Tue, 19 Oct 2021 16:44:13 +0300 Subject: [PATCH] vmalert: make group.ID() thread-safe (#1726) Commit fixes potential race condition when group update and generating of ID() happens simultaneously. Signed-off-by: hagen1778 --- app/vmalert/group.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/vmalert/group.go b/app/vmalert/group.go index e80b1e6e8..47fab99d2 100644 --- a/app/vmalert/group.go +++ b/app/vmalert/group.go @@ -123,6 +123,9 @@ func (g *Group) newRule(qb datasource.QuerierBuilder, rule config.Rule) Rule { // ID return unique group ID that consists of // rules file and group name func (g *Group) ID() uint64 { + g.mu.RLock() + defer g.mu.RUnlock() + hash := fnv.New64a() hash.Write([]byte(g.File)) hash.Write([]byte("\xff"))