docker: sync access to exit result within a handle

This commit is contained in:
Nick Ethier
2018-11-20 20:41:32 -05:00
parent ace09b3a84
commit fc53f5f635
3 changed files with 19 additions and 5 deletions

View File

@@ -83,8 +83,7 @@ type Driver struct {
// coordinator is what tracks multiple image pulls against the same docker image
coordinator *dockerCoordinator
// logger will log to the plugin output which is usually an 'executor.out'
// file located in the root of the TaskDir
// logger will log to the Nomad agent
logger hclog.Logger
}
@@ -990,7 +989,7 @@ func (d *Driver) handleWait(ctx context.Context, ch chan *drivers.ExitResult, h
defer close(ch)
select {
case <-h.waitCh:
ch <- h.exitResult
ch <- h.ExitResult()
case <-ctx.Done():
ch <- &drivers.ExitResult{
Err: ctx.Err(),
@@ -1080,7 +1079,7 @@ func (d *Driver) InspectTask(taskID string) (*drivers.TaskStatus, error) {
"container_id": container.ID,
},
NetworkOverride: h.net,
ExitResult: h.exitResult,
ExitResult: h.ExitResult(),
}
status.State = drivers.TaskStateUnknown

View File

@@ -38,7 +38,14 @@ type taskHandle struct {
net *structs.DriverNetwork
imageID string
exitResult *drivers.ExitResult
exitResult *drivers.ExitResult
exitResultLock sync.Mutex
}
func (h *taskHandle) ExitResult() *drivers.ExitResult {
h.exitResultLock.Lock()
defer h.exitResultLock.Unlock()
return h.exitResult.Copy()
}
type taskHandleState struct {
@@ -202,12 +209,14 @@ func (h *taskHandle) run() {
}
// Set the result
h.exitResultLock.Lock()
h.exitResult = &drivers.ExitResult{
ExitCode: exitCode,
Signal: 0,
OOMKilled: oom,
Err: werr,
}
h.exitResultLock.Unlock()
close(h.waitCh)
}

View File

@@ -249,6 +249,12 @@ func (r *ExitResult) Successful() bool {
return r.ExitCode == 0 && r.Signal == 0 && r.Err == nil
}
func (r *ExitResult) Copy() *ExitResult {
res := new(ExitResult)
*res = *r
return res
}
type TaskStatus struct {
ID string
Name string