From 9c87d22fadf936de061afd738976cbe047279f68 Mon Sep 17 00:00:00 2001 From: talsabagport Date: Wed, 14 Dec 2022 16:58:27 +0200 Subject: [PATCH] Fix concurrent map writes panic when using gojq query.Run on same object in parallel --- pkg/jq/parser.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/jq/parser.go b/pkg/jq/parser.go index c4e28fd..73a5e1d 100644 --- a/pkg/jq/parser.go +++ b/pkg/jq/parser.go @@ -4,15 +4,20 @@ import ( "fmt" "github.com/itchyny/gojq" "strings" + "sync" ) +var mutex = &sync.Mutex{} + func runJQQuery(jqQuery string, obj interface{}) (interface{}, error) { query, err := gojq.Parse(jqQuery) if err != nil { return nil, err } + mutex.Lock() queryRes, ok := query.Run(obj).Next() + mutex.Unlock() if !ok { return nil, fmt.Errorf("query should return at least one value")