From 5fd2f827357a1e6b60a33ca63e5e2c04fd8c2f79 Mon Sep 17 00:00:00 2001 From: silverwind <2021+silverwind@noreply.gitea.com> Date: Thu, 29 Oct 2026 16:46:53 +0000 Subject: [PATCH] test: fix race in TestTreeKillCancelBeforeCaptureKillsTree (#1360) `TestTreeKillCancelBeforeCaptureKillsTree` fails intermittently on CI, e.g. https://gitea.com/gitea/runner/actions/runs/1155856. Dash, the Ubuntu `/bin/sh`, points a background job's stdin at `/dev/null` before applying its redirections, so `cat <&0 &` read EOF and exited at once and the liveness check raced it. The pipe is now handed over on fd 3, which dash leaves alone. Introduced in https://gitea.com/gitea/runner/pulls/1338 Reviewed-on: https://gitea.com/gitea/runner/pulls/1360 Reviewed-by: Zettat123 <39446+zettat123@noreply.gitea.com> --- internal/pkg/process/killer_unix_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pkg/process/killer_unix_test.go b/internal/pkg/process/killer_unix_test.go index 9fa859ad..e1fef639 100644 --- a/internal/pkg/process/killer_unix_test.go +++ b/internal/pkg/process/killer_unix_test.go @@ -104,7 +104,7 @@ func TestTreeKillCancelBeforeCaptureKillsTree(t *testing.T) { require.NoError(t, err) t.Cleanup(func() { _ = stdin.Close() }) t.Cleanup(func() { _ = input.Close() }) - cmd := exec.CommandContext(t.Context(), "/bin/sh", "-c", "cat <&0 & echo $!; read value") + cmd := exec.CommandContext(t.Context(), "/bin/sh", "-c", "exec 3<&0; cat <&3 & echo $!; read value") cmd.Stdin = stdin cmd.SysProcAttr = SysProcAttr("", false) output, err := cmd.StdoutPipe()