From f479c290550d59e44107beee443f05f8136b5c05 Mon Sep 17 00:00:00 2001 From: Sawjan Gurung Date: Mon, 18 Dec 2023 16:01:55 +0545 Subject: [PATCH] close channel after log scanner has completed (#7997) --- tests/ociswrapper/ocis/ocis.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/ociswrapper/ocis/ocis.go b/tests/ociswrapper/ocis/ocis.go index 815b8c1abd..49cba3bd98 100644 --- a/tests/ociswrapper/ocis/ocis.go +++ b/tests/ociswrapper/ocis/ocis.go @@ -9,6 +9,7 @@ import ( "os/exec" "strconv" "strings" + "sync" "syscall" "time" @@ -22,6 +23,10 @@ var retryCount = 0 var stopSignal = false func Start(envMap map[string]any) { + // wait for the log scanner to finish + var wg sync.WaitGroup + wg.Add(2) + stopSignal = false if retryCount == 0 { defer common.Wg.Done() @@ -57,12 +62,14 @@ func Start(envMap map[string]any) { // Read the logs when the 'ocis server' command is running go func() { + defer wg.Done() for logScanner.Scan() { outChan <- logScanner.Text() } }() go func() { + defer wg.Done() for outputScanner.Scan() { outChan <- outputScanner.Text() } @@ -89,6 +96,7 @@ func Start(envMap map[string]any) { retryCount++ maxRetry, _ := strconv.Atoi(config.Get("retry")) if retryCount <= maxRetry { + wg.Wait() close(outChan) log.Println(fmt.Sprintf("Retry starting oCIS server... (retry %v)", retryCount)) // wait 500 milliseconds before retrying @@ -99,6 +107,7 @@ func Start(envMap map[string]any) { } } } + wg.Wait() close(outChan) }