Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: concurrent map read and write error #2867

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions internal/providers/terraform/terragrunt_hcl_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var (
terragruntDownloadedDirs = sync.Map{}

terragruntOutputCache = &TerragruntOutputCache{
cache: map[string]cty.Value{},
cache: sync.Map{},
mu: &infSync.KeyMutex{},
}
)
Expand All @@ -71,7 +71,7 @@ func (p panicError) Error() string {
}

type TerragruntOutputCache struct {
cache map[string]cty.Value
cache sync.Map
mu *infSync.KeyMutex
}

Expand All @@ -82,17 +82,19 @@ func (o *TerragruntOutputCache) Set(key string, getVal func() (cty.Value, error)
unlock := o.mu.Lock(key)
defer unlock()

val, ok := o.cache[key]
if ok {
return val, nil
cacheVal, exists := o.cache.Load(key)
if exists {
if val, ok := cacheVal.(cty.Value); ok {
return val, nil
}
}

val, err := getVal()
if err != nil {
return cty.NilVal, err
}

o.cache[key] = val
o.cache.Store(key, val)
return val, nil
}

Expand Down