From a95115a6da7aa46980f42d02cc9c2dd9faea08ea Mon Sep 17 00:00:00 2001 From: Thomas Jackson Date: Thu, 30 Mar 2023 08:10:25 -0700 Subject: [PATCH] Add missing lock to ExtractSelectors Now that we are parallel walking we need to ensure that the visitor methods are concurrent-safe. Surprisingly this doesn't show up in `-race Fixes https://github.com/jacksontj/promxy/issues/579 --- promql/parser/ast.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/promql/parser/ast.go b/promql/parser/ast.go index 4e8f4daa5f..d9117b988e 100644 --- a/promql/parser/ast.go +++ b/promql/parser/ast.go @@ -382,11 +382,16 @@ func Walk(ctx context.Context, v Visitor, s *EvalStmt, node Node, path []Node, n } func ExtractSelectors(expr Expr) [][]*labels.Matcher { - var selectors [][]*labels.Matcher + var ( + selectors [][]*labels.Matcher + l sync.Mutex + ) Inspect(context.TODO(), &EvalStmt{Expr: expr}, func(node Node, _ []Node) error { vs, ok := node.(*VectorSelector) if ok { + l.Lock() selectors = append(selectors, vs.LabelMatchers) + l.Unlock() } return nil }, nil)