Skip to content

Commit

Permalink
Merge pull request #18894 from hashicorp/b-state-locking
Browse files Browse the repository at this point in the history
Make sure the state is locked before it is used
  • Loading branch information
Sander van Harmelen authored Sep 18, 2018
2 parents 813b5fd + 36bd5d6 commit 76a4621
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions command/taint.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ func (c *TaintCommand) Run(args []string) int {
c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err))
return 1
}
if err := st.RefreshState(); err != nil {
c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err))
return 1
}

if c.stateLock {
stateLocker := clistate.NewLocker(context.Background(), c.stateLockTimeout, c.Ui, c.Colorize())
Expand All @@ -91,6 +87,11 @@ func (c *TaintCommand) Run(args []string) int {
defer stateLocker.Unlock(nil)
}

if err := st.RefreshState(); err != nil {
c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err))
return 1
}

// Get the actual state structure
s := st.State()
if s.Empty() {
Expand Down
9 changes: 5 additions & 4 deletions command/untaint.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ func (c *UntaintCommand) Run(args []string) int {
c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err))
return 1
}
if err := st.RefreshState(); err != nil {
c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err))
return 1
}

if c.stateLock {
stateLocker := clistate.NewLocker(context.Background(), c.stateLockTimeout, c.Ui, c.Colorize())
Expand All @@ -79,6 +75,11 @@ func (c *UntaintCommand) Run(args []string) int {
defer stateLocker.Unlock(nil)
}

if err := st.RefreshState(); err != nil {
c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err))
return 1
}

// Get the actual state structure
s := st.State()
if s.Empty() {
Expand Down

0 comments on commit 76a4621

Please sign in to comment.