terraform: share graph walker's variables lock w/ interpolater

The ContextGraphWalker struct includes a lock that's passed down to
BuiltinEvalContext and guards access to interpolation variables as
they're written using SetVariables.

The likely problem being expressed in #5733 is that the same map
reference is also passed down to the Interpolater.Variables field, which
is used for variable lookup.

Here, we plumb the same lock we're using to guard access for writes down
and acquire it before doing variable reads as well. It's not as fine
grained as perhaps it could be, but all the context tests pass and I
believe this should address #5733.
This commit is contained in:
Paul Hinze 2016-03-21 18:17:18 -05:00
parent 293c6ca68c
commit 024dcc9d32
2 changed files with 14 additions and 10 deletions

View File

@ -86,6 +86,7 @@ func (w *ContextGraphWalker) EnterPath(path []string) EvalContext {
State: w.Context.state, State: w.Context.state,
StateLock: &w.Context.stateLock, StateLock: &w.Context.stateLock,
Variables: variables, Variables: variables,
VariablesLock: &w.interpolaterVarLock,
}, },
InterpolaterVars: w.interpolaterVars, InterpolaterVars: w.interpolaterVars,
InterpolaterVarLock: &w.interpolaterVarLock, InterpolaterVarLock: &w.interpolaterVarLock,

View File

@ -28,6 +28,7 @@ type Interpolater struct {
State *State State *State
StateLock *sync.RWMutex StateLock *sync.RWMutex
Variables map[string]string Variables map[string]string
VariablesLock *sync.Mutex
} }
// InterpolationScope is the current scope of execution. This is required // InterpolationScope is the current scope of execution. This is required
@ -273,6 +274,8 @@ func (i *Interpolater) valueUserVar(
n string, n string,
v *config.UserVariable, v *config.UserVariable,
result map[string]ast.Variable) error { result map[string]ast.Variable) error {
i.VariablesLock.Lock()
defer i.VariablesLock.Unlock()
val, ok := i.Variables[v.Name] val, ok := i.Variables[v.Name]
if ok { if ok {
result[n] = ast.Variable{ result[n] = ast.Variable{