Skip to content

Commit

Permalink
Merge pull request #4 from port-labs/PORT-2238-k-8-s-exporter-panic-w…
Browse files Browse the repository at this point in the history
…hen-configuring-the-same-kind-multiple-times

Fix concurrent map writes panic when using gojq query.Run on same object in parallel
  • Loading branch information
talsabagport authored Dec 14, 2022
2 parents 7d941c1 + 9c87d22 commit 798ad86
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/jq/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 798ad86

Please sign in to comment.