rawexec: fix race around h.procState

This commit is contained in:
Michael Schurter 2018-10-30 17:15:47 -07:00
parent ac12ae1729
commit 616801417c

View file

@ -27,19 +27,25 @@ type rawExecTaskHandle struct {
}
func (h *rawExecTaskHandle) IsRunning() bool {
h.stateLock.RLock()
defer h.stateLock.RUnlock()
return h.procState == drivers.TaskStateRunning
}
func (h *rawExecTaskHandle) run() {
// since run is called immediately after the handle is created this
// Since run is called immediately after the handle is created this
// ensures the exitResult is initialized so we avoid a nil pointer
// thus it does not need to be included in the lock
// thus it does not need to be included in the lock.
h.stateLock.Lock()
if h.exitResult == nil {
h.exitResult = &drivers.ExitResult{}
}
h.stateLock.Unlock()
// Block until process exits
ps, err := h.exec.Wait()
h.stateLock.Lock()
defer h.stateLock.Unlock()