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>
This commit is contained in:
silverwind
2026-10-29 16:46:53 +00:00
parent c6567296a0
commit 5fd2f82735

View File

@@ -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()