Skip to content

Commit

Permalink
Lock contention fix (#54)
Browse files Browse the repository at this point in the history
* Fix lock contention in package vars

* Update tests for vars fixes
  • Loading branch information
vladimirvivien authored Nov 3, 2024
1 parent 1ce1b90 commit f294aef
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions vars/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ func (v *Variables) Vars(variables ...string) *Variables {

// SetVar declares a gexe session variable.
func (v *Variables) SetVar(name, value string) *Variables {
expVar := v.ExpandVar(value, v.Val)
v.Lock()
defer v.Unlock()
v.vars[name] = v.ExpandVar(value, v.Val)
v.vars[name] = expVar
return v
}

Expand All @@ -104,8 +105,8 @@ func (v *Variables) UnsetVar(name string) *Variables {
// Val searches for a gexe session variable with provided key, if not found
// searches for an environment variable with that key.
func (v *Variables) Val(key string) string {
//v.Lock()
//defer v.Unlock()
v.RLock()
defer v.RUnlock()
if val, ok := v.vars[key]; ok {
return val
}
Expand Down

0 comments on commit f294aef

Please sign in to comment.