From 06f22549625337bc63169792f7545190bbf44f52 Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Thu, 13 Mar 2025 11:12:15 -0700 Subject: [PATCH] Deflake TestExecProcList. There is a race in the test where the goroutine running Container.executeSync() calls WaitPID() => IsSandboxRunning() which accesses Container.Sandbox. This can race with the defer Container.Destroy which sets Sandbox = nil. This race was introduced in 0968254ce715 ("Speed up container_test") which got rid of the read on channel `ch`. Fix the race by exec-ing asynchronously. This maintains the old behavior of not checking if the exit status of sleep. Fixes 0968254ce715 ("Speed up container_test") PiperOrigin-RevId: 736572600 --- runsc/container/container_test.go | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/runsc/container/container_test.go b/runsc/container/container_test.go index 410c54071..9eab25efb 100644 --- a/runsc/container/container_test.go +++ b/runsc/container/container_test.go @@ -921,24 +921,17 @@ func TestExecProcList(t *testing.T) { KUID: uid, } - // Verify that "sleep 100" and "sleep 5" are running after exec. First, - // start running exec (which blocks). - ch := make(chan error) - go func() { - exitStatus, err := cont.executeSync(conf, execArgs) - if err != nil { - ch <- err - } else if exitStatus != 0 { - ch <- fmt.Errorf("failed with exit status: %v", exitStatus) - } else { - ch <- nil - } - }() + // Verify that "sleep 1000" and "sleep 5" are running after exec. First, + // start running exec asynchronously. + pid2, err := cont.Execute(conf, execArgs) + if err != nil { + t.Fatalf("error executing 'sleep 5' command: %v", err) + } // expectedPL lists the expected process state of the container. expectedPL := []*control.Process{ newProcessBuilder().PID(1).PPID(0).Cmd("sleep").UID(0).Process(), - newProcessBuilder().PID(2).PPID(0).Cmd("sleep").UID(uid).Process(), + newProcessBuilder().PID(kernel.ThreadID(pid2)).PPID(0).Cmd("sleep").UID(uid).Process(), } if err := waitForProcessList(cont, expectedPL); err != nil { t.Fatalf("error waiting for processes: %v", err)