From b315a85a6695dfbe67767f21713c3ccfc7cae73e Mon Sep 17 00:00:00 2001
From: jingrui <jingrui@huawei.com>
Date: Mon, 1 Feb 2021 09:48:07 +0800
Subject: [PATCH] containerd: fix dead loop

Change-Id: I6b2ce4456ca8fe197683692721d150f4e5d7e3fe
Signed-off-by: jingrui <jingrui@huawei.com>
---
 runtime/v1/shim/client/client.go | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/runtime/v1/shim/client/client.go b/runtime/v1/shim/client/client.go
index 06453b35a..9e63af4ea 100644
--- a/runtime/v1/shim/client/client.go
+++ b/runtime/v1/shim/client/client.go
@@ -393,15 +393,15 @@ func (c *Client) signalShim(ctx context.Context, sig syscall.Signal) error {
 
 func (c *Client) waitForExit(pid int) <-chan struct{} {
 	c.exitOnce.Do(func() {
-		for {
+		for i := 0; i < 1000; i++ {
 			// use kill(pid, 0) here because the shim could have been reparented
 			// and we are no longer able to waitpid(pid, ...) on the shim
 			if err := unix.Kill(pid, 0); err == unix.ESRCH {
-				close(c.exitCh)
-				return
+				break
 			}
 			time.Sleep(10 * time.Millisecond)
 		}
+		close(c.exitCh)
 	})
 	return c.exitCh
 }
-- 
2.17.1

