From b3623a2c40f2a8d18c5c9b453c48f00486ebe893 Mon Sep 17 00:00:00 2001 From: "fupan.lfp" Date: Wed, 23 Jun 2021 19:20:28 +0800 Subject: [PATCH] shimv2: fix the issue of leaking wait goroutines After create an container/exec successfully, containerd would wait it immediately, and if start it failed, there is no chance to send value to exitCh, thus the wait goroutine would blocked for ever and had no chance to exit. Fixes: #2087 Signed-off-by: fupan.lfp --- src/runtime/containerd-shim-v2/start.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/runtime/containerd-shim-v2/start.go b/src/runtime/containerd-shim-v2/start.go index 224ea074c2..5eede489f3 100644 --- a/src/runtime/containerd-shim-v2/start.go +++ b/src/runtime/containerd-shim-v2/start.go @@ -13,7 +13,13 @@ import ( "github.com/kata-containers/kata-containers/src/runtime/pkg/katautils" ) -func startContainer(ctx context.Context, s *service, c *container) error { +func startContainer(ctx context.Context, s *service, c *container) (retErr error) { + defer func() { + if retErr != nil { + // notify the wait goroutine to continue + c.exitCh <- exitCode255 + } + }() // start a container if c.cType == "" { err := fmt.Errorf("Bug, the container %s type is empty", c.id) @@ -87,7 +93,7 @@ func startContainer(ctx context.Context, s *service, c *container) error { return nil } -func startExec(ctx context.Context, s *service, containerID, execID string) (*exec, error) { +func startExec(ctx context.Context, s *service, containerID, execID string) (e *exec, retErr error) { // start an exec c, err := s.getContainer(containerID) if err != nil { @@ -99,6 +105,13 @@ func startExec(ctx context.Context, s *service, containerID, execID string) (*ex return nil, err } + defer func() { + if retErr != nil { + // notify the wait goroutine to continue + execs.exitCh <- exitCode255 + } + }() + _, proc, err := s.sandbox.EnterContainer(ctx, containerID, *execs.cmds) if err != nil { err := fmt.Errorf("cannot enter container %s, with err %s", containerID, err)