Skip to content

Commit

Permalink
Gate task.Wait status check on checkpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
  • Loading branch information
crosbymichael committed Aug 3, 2017
1 parent 9f13b41 commit fdc5a47
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
goruntime "runtime"
"strings"
"sync"
"syscall"

eventsapi "github.com/containerd/containerd/api/services/events/v1"
Expand Down Expand Up @@ -93,6 +94,7 @@ type task struct {
id string
pid uint32

mu sync.Mutex
deferred *tasks.CreateTaskRequest
}

Expand All @@ -102,9 +104,14 @@ func (t *task) Pid() uint32 {
}

func (t *task) Start(ctx context.Context) error {
if t.deferred != nil {
response, err := t.client.TaskService().Create(ctx, t.deferred)
t.mu.Lock()
deferred := t.deferred
t.mu.Unlock()
if deferred != nil {
response, err := t.client.TaskService().Create(ctx, deferred)
t.mu.Lock()
t.deferred = nil
t.mu.Unlock()
if err != nil {
t.io.closer.Close()
return err
Expand Down Expand Up @@ -166,13 +173,18 @@ func (t *task) Wait(ctx context.Context) (uint32, error) {
if err != nil {
return UnknownExitStatus, errdefs.FromGRPC(err)
}
// first check if the task has exited
status, err := t.Status(ctx)
if err != nil {
return UnknownExitStatus, errdefs.FromGRPC(err)
}
if status.Status == Stopped {
return status.ExitStatus, nil
t.mu.Lock()
checkpoint := t.deferred != nil
t.mu.Unlock()
if !checkpoint {
// first check if the task has exited
status, err := t.Status(ctx)
if err != nil {
return UnknownExitStatus, errdefs.FromGRPC(err)
}
if status.Status == Stopped {
return status.ExitStatus, nil
}
}
for {
evt, err := eventstream.Recv()
Expand Down

0 comments on commit fdc5a47

Please sign in to comment.