diff --git a/containerd-shim-v2/container.go b/containerd-shim-v2/container.go index e56a4bce9..5fc252be6 100644 --- a/containerd-shim-v2/container.go +++ b/containerd-shim-v2/container.go @@ -21,7 +21,7 @@ type container struct { s *service ttyio *ttyIO spec *oci.CompatOCISpec - time time.Time + exitTime time.Time execs map[string]*exec exitIOch chan struct{} exitCh chan uint32 @@ -61,7 +61,6 @@ func newContainer(s *service, r *taskAPI.CreateTaskRequest, containerType vc.Con status: task.StatusCreated, exitIOch: make(chan struct{}), exitCh: make(chan uint32, 1), - time: time.Now(), } return c, nil } diff --git a/containerd-shim-v2/service.go b/containerd-shim-v2/service.go index f927e5ac6..e8cdc947b 100644 --- a/containerd-shim-v2/service.go +++ b/containerd-shim-v2/service.go @@ -444,12 +444,12 @@ func (s *service) Delete(ctx context.Context, r *taskAPI.DeleteRequest) (_ *task ContainerID: s.id, Pid: s.pid, ExitStatus: c.exit, - ExitedAt: c.time, + ExitedAt: c.exitTime, }) return &taskAPI.DeleteResponse{ ExitStatus: c.exit, - ExitedAt: c.time, + ExitedAt: c.exitTime, Pid: s.pid, }, nil } @@ -860,6 +860,7 @@ func (s *service) Wait(ctx context.Context, r *taskAPI.WaitRequest) (_ *taskAPI. return &taskAPI.WaitResponse{ ExitStatus: ret, + ExitedAt: c.exitTime, }, nil } diff --git a/containerd-shim-v2/wait.go b/containerd-shim-v2/wait.go index 6b986a72e..121cad47b 100644 --- a/containerd-shim-v2/wait.go +++ b/containerd-shim-v2/wait.go @@ -41,18 +41,12 @@ func wait(s *service, c *container, execID string) (int32, error) { }).Error("Wait for process failed") } - if execID == "" { - c.exitCh <- uint32(ret) - } else { - execs.exitCh <- uint32(ret) - } - timeStamp := time.Now() c.mu.Lock() if execID == "" { c.status = task.StatusStopped c.exit = uint32(ret) - c.time = timeStamp + c.exitTime = timeStamp } else { execs.status = task.StatusStopped execs.exitCode = ret @@ -60,6 +54,12 @@ func wait(s *service, c *container, execID string) (int32, error) { } c.mu.Unlock() + if execID == "" { + c.exitCh <- uint32(ret) + } else { + execs.exitCh <- uint32(ret) + } + go cReap(s, int(ret), c.id, execID, timeStamp) return ret, nil