From 07605707cce769e4f4c79b700586b5c59ec0b15a Mon Sep 17 00:00:00 2001 From: xiadanni1 Date: Sat, 13 Jul 2019 06:32:54 +0800 Subject: [PATCH] containerd: add shim exit when bundle dir does not exist reason: when bundle dir is deleted, containerd-shim should exit to avoid shim.sock is occupied when container restart next time. Change-Id: I956412598e17d15f25b91afe1cbb9e24463f04be Signed-off-by: xiadanni1 --- runtime/v1/shim/service.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/runtime/v1/shim/service.go b/runtime/v1/shim/service.go index 8adaf35..ac545ea 100644 --- a/runtime/v1/shim/service.go +++ b/runtime/v1/shim/service.go @@ -141,13 +141,23 @@ func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (_ * } rootfs := filepath.Join(r.Bundle, "rootfs") defer func() { + go func() { + for i := 0; i < 60; i++ { + time.Sleep(time.Second) + _, err := os.Stat(r.Bundle) + if os.IsNotExist(err) { + logrus.Errorf("bundle dir: %v does not exist, containerd-shim exit", r.Bundle) + os.Exit(0) + } + } + }() if err != nil { logrus.Errorf("create init %s failed error=%v", r.ID, err) if err2 := mount.UnmountAll(rootfs, 0); err2 != nil { log.G(ctx).WithError(err2).Warn("Failed to cleanup rootfs mount") } go func() { - time.Sleep(10*time.Second) + time.Sleep(10 * time.Second) os.Exit(0) }() } -- 1.8.3.1