From 6875e8d6b48ca505f30b91777b4cf9e23d97b54a Mon Sep 17 00:00:00 2001 From: "Michael S. Fischer" Date: Wed, 5 Aug 2015 09:06:51 -0700 Subject: [PATCH] lock.go: fix race condition Fix a race condition between startChild() and killChild() that could lead to an orphaned managed process. Fixes #1155 --- command/lock.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/command/lock.go b/command/lock.go index 51b5e2d163..8b74f3b88f 100644 --- a/command/lock.go +++ b/command/lock.go @@ -47,7 +47,7 @@ Usage: consul lock [options] prefix child... disrupted the child process will be sent a SIGTERM signal and given time to gracefully exit. After the grace period expires the process will be hard terminated. - For Consul agents on Windows, the child process is always hard + For Consul agents on Windows, the child process is always hard terminated with a SIGKILL, since Windows has no POSIX compatible notion for SIGTERM. @@ -268,13 +268,14 @@ func (c *LockCommand) startChild(script string, doneCh chan struct{}) error { cmd.Stderr = os.Stderr // Start the child process + c.childLock.Lock() if err := cmd.Start(); err != nil { c.Ui.Error(fmt.Sprintf("Error starting handler: %s", err)) + c.childLock.Unlock() return err } // Setup the child info - c.childLock.Lock() c.child = cmd.Process c.childLock.Unlock()