From 81ed269ed2f742984ab0a1cca9e4c62acf8a3cc6 Mon Sep 17 00:00:00 2001 From: bin Date: Mon, 28 Feb 2022 16:52:49 +0800 Subject: [PATCH] runtime: use Cmd.StdoutPipe instead of self-created pipe Nydusd uses a bufio.Scanner to check if nydusd process has existed, but stderr/stdout passed to Cmd is self-created pipe, this pipe will not be closed if the process start failing. Use standard Cmd.StdoutPipe can close the stdout and kata shim will detect the existence of the nydusd process, then call cmd.Wait to reap the process' resources. Fixes: #3783 Signed-off-by: bin --- src/runtime/virtcontainers/nydusd.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/runtime/virtcontainers/nydusd.go b/src/runtime/virtcontainers/nydusd.go index c9315ee370..7931e4556d 100644 --- a/src/runtime/virtcontainers/nydusd.go +++ b/src/runtime/virtcontainers/nydusd.go @@ -104,12 +104,13 @@ func (nd *nydusd) Start(ctx context.Context, onQuit onQuitFunc) (int, error) { return pid, err } cmd := exec.Command(nd.path, args...) - r, w, err := os.Pipe() + stdout, err := cmd.StdoutPipe() if err != nil { return pid, err } - cmd.Stdout = w - cmd.Stderr = w + + cmd.Stderr = cmd.Stdout + fields := logrus.Fields{ "path": nd.path, "args": strings.Join(args, " "), @@ -120,7 +121,7 @@ func (nd *nydusd) Start(ctx context.Context, onQuit onQuitFunc) (int, error) { } // Monitor nydusd's stdout/stderr and stop sandbox if nydusd quits go func() { - scanner := bufio.NewScanner(r) + scanner := bufio.NewScanner(stdout) for scanner.Scan() { nd.Logger().Info(scanner.Text()) }