Merge pull request #1214 from zendesk/fix_lock_race_2

lock.go: fix another race condition
This commit is contained in:
Armon Dadgar 2015-09-02 16:04:55 -07:00
commit 56efa4958b
1 changed files with 4 additions and 3 deletions

View File

@ -185,7 +185,10 @@ func (c *LockCommand) Run(args []string) int {
goto RELEASE goto RELEASE
} }
// Kill the child // Prevent starting a new child. The lock is never released
// after this point.
c.childLock.Lock()
// Kill any existing child
if err := c.killChild(childDone); err != nil { if err := c.killChild(childDone); err != nil {
c.Ui.Error(fmt.Sprintf("%s", err)) c.Ui.Error(fmt.Sprintf("%s", err))
} }
@ -318,9 +321,7 @@ func (c *LockCommand) startChild(script string, doneCh chan struct{}, passStdin
// on the first attempt. // on the first attempt.
func (c *LockCommand) killChild(childDone chan struct{}) error { func (c *LockCommand) killChild(childDone chan struct{}) error {
// Get the child process // Get the child process
c.childLock.Lock()
child := c.child child := c.child
c.childLock.Unlock()
// If there is no child process (failed to start), we can quit early // If there is no child process (failed to start), we can quit early
if child == nil { if child == nil {