From 4b7cd84eafb09bf4b6bcd4731261935200e0e4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Wei=C3=9Fe?= <66256922+daniel-weisse@users.noreply.github.com> Date: Mon, 28 Oct 2024 11:34:11 +0100 Subject: [PATCH] e2e-upgrade: guard function return values behind `sync.WaitGroup` (#3461) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Weiße --- e2e/internal/upgrade/upgrade.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/e2e/internal/upgrade/upgrade.go b/e2e/internal/upgrade/upgrade.go index b021eb5d9b..2dd283ef85 100644 --- a/e2e/internal/upgrade/upgrade.go +++ b/e2e/internal/upgrade/upgrade.go @@ -182,7 +182,8 @@ func runCommandWithSeparateOutputs(cmd *exec.Cmd) (stdout, stderr []byte, err er return } - continuouslyPrintOutput := func(r io.Reader, prefix string) { + continuouslyPrintOutput := func(r io.Reader, prefix string, wg *sync.WaitGroup) { + defer wg.Done() scanner := bufio.NewScanner(r) for scanner.Scan() { output := scanner.Text() @@ -196,12 +197,15 @@ func runCommandWithSeparateOutputs(cmd *exec.Cmd) (stdout, stderr []byte, err er } } - go continuouslyPrintOutput(stdoutIn, "stdout") - go continuouslyPrintOutput(stderrIn, "stderr") + wg := &sync.WaitGroup{} + wg.Add(2) + go continuouslyPrintOutput(stdoutIn, "stdout", wg) + go continuouslyPrintOutput(stderrIn, "stderr", wg) if err = cmd.Wait(); err != nil { err = fmt.Errorf("wait for command to finish: %w", err) } + wg.Wait() return stdout, stderr, err }