terraform: write lock on post state updates
Found race here: https://travis-ci.org/hashicorp/terraform/builds/177814212 Since WriteState calls `prune` and `init`, we're actually modifying the state structure so we need a full write lock to perform this operation.
This commit is contained in:
parent
e0d5d991d9
commit
b6687aa287
|
@ -107,9 +107,10 @@ type EvalUpdateStateHook struct{}
|
|||
func (n *EvalUpdateStateHook) Eval(ctx EvalContext) (interface{}, error) {
|
||||
state, lock := ctx.State()
|
||||
|
||||
// Get a read lock so it doesn't change while we're calling this
|
||||
lock.RLock()
|
||||
defer lock.RUnlock()
|
||||
// Get a full lock. Even calling something like WriteState can modify
|
||||
// (prune) the state, so we need the full lock.
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
|
||||
// Call the hook
|
||||
err := ctx.Hook(func(h Hook) (HookAction, error) {
|
||||
|
|
Loading…
Reference in New Issue