Skip to content

Commit

Permalink
Fix concurrency issue
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Jan 18, 2023
1 parent 7535f31 commit a4deb49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 0.2.2
## 0.2.3 (unreleased)

- Fix crash due to concurrency issue

## 0.2.2

- Do not merge YAML dictionary list items, where each list item has unique attributes with primitive values

Expand Down
6 changes: 6 additions & 0 deletions internal/provider/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"errors"
"fmt"
"os"
"sync"

"gopkg.in/yaml.v3"
)

var tagResolvers = make(map[string]func(*yaml.Node) (*yaml.Node, error))
var tagResolversMutex = &sync.Mutex{}

type CustomTagProcessor struct {
target interface{}
Expand All @@ -23,11 +25,13 @@ func (i *CustomTagProcessor) UnmarshalYAML(value *yaml.Node) error {
}

func resolveTags(node *yaml.Node) (*yaml.Node, error) {
tagResolversMutex.Lock()
for tag, fn := range tagResolvers {
if node.Tag == tag {
return fn(node)
}
}
tagResolversMutex.Unlock()
if node.Kind == yaml.SequenceNode || node.Kind == yaml.MappingNode {
var err error
for i := range node.Content {
Expand All @@ -53,7 +57,9 @@ func resolveEnv(node *yaml.Node) (*yaml.Node, error) {
}

func AddResolvers(tag string, fn func(*yaml.Node) (*yaml.Node, error)) {
tagResolversMutex.Lock()
tagResolvers[tag] = fn
tagResolversMutex.Unlock()
}

func YamlUnmarshal(in []byte, out interface{}) error {
Expand Down

0 comments on commit a4deb49

Please sign in to comment.