Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: synchronize exitState accesses #5433

Merged
merged 1 commit into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions drivers/shared/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"runtime"
"strings"
"sync"
"syscall"
"time"

Expand Down Expand Up @@ -212,6 +213,8 @@ type UniversalExecutor struct {
commandCfg *ExecCommand

exitState *ProcessState
exitStateLock sync.Mutex

processExited chan interface{}

// resConCtx is used to track and cleanup additional resources created by
Expand Down Expand Up @@ -364,6 +367,8 @@ func (e *UniversalExecutor) Wait(ctx context.Context) (*ProcessState, error) {
case <-ctx.Done():
return nil, ctx.Err()
case <-e.processExited:
e.exitStateLock.Lock()
defer e.exitStateLock.Unlock()
return e.exitState, nil
}
}
Expand All @@ -378,7 +383,9 @@ func (e *UniversalExecutor) wait() {
pid := e.childCmd.Process.Pid
err := e.childCmd.Wait()
if err == nil {
e.exitStateLock.Lock()
e.exitState = &ProcessState{Pid: pid, ExitCode: 0, Time: time.Now()}
e.exitStateLock.Unlock()
return
}

Expand All @@ -404,7 +411,9 @@ func (e *UniversalExecutor) wait() {
e.logger.Warn("unexpected Cmd.Wait() error type", "error", err)
}

e.exitStateLock.Lock()
e.exitState = &ProcessState{Pid: pid, ExitCode: exitCode, Signal: signal, Time: time.Now()}
e.exitStateLock.Unlock()
}

var (
Expand Down
12 changes: 11 additions & 1 deletion drivers/shared/executor/executor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path"
"path/filepath"
"strings"
"sync"
"syscall"
"time"

Expand Down Expand Up @@ -78,7 +79,9 @@ type LibcontainerExecutor struct {
container libcontainer.Container
userProc *libcontainer.Process
userProcExited chan interface{}
exitState *ProcessState

exitState *ProcessState
exitStateLock sync.Mutex
}

func NewExecutorWithIsolation(logger hclog.Logger) Executor {
Expand Down Expand Up @@ -248,6 +251,8 @@ func (l *LibcontainerExecutor) Wait(ctx context.Context) (*ProcessState, error)
case <-ctx.Done():
return nil, ctx.Err()
case <-l.userProcExited:
l.exitStateLock.Lock()
defer l.exitStateLock.Unlock()
return l.exitState, nil
}
}
Expand All @@ -263,7 +268,10 @@ func (l *LibcontainerExecutor) wait() {
ps = exitErr.ProcessState
} else {
l.logger.Error("failed to call wait on user process", "error", err)
l.exitStateLock.Lock()
l.exitState = &ProcessState{Pid: 0, ExitCode: 1, Time: time.Now()}
l.exitStateLock.Unlock()

return
}
}
Expand All @@ -281,12 +289,14 @@ func (l *LibcontainerExecutor) wait() {
}
}

l.exitStateLock.Lock()
l.exitState = &ProcessState{
Pid: ps.Pid(),
ExitCode: exitCode,
Signal: signal,
Time: time.Now(),
}
l.exitStateLock.Unlock()
}

// Shutdown stops all processes started and cleans up any resources
Expand Down