From 2c5f5a1485982adb69154ce2cb455a96673490b7 Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 18:38:16 +0000 Subject: [PATCH] test(e2e): keep the planted zombie until its shell has exec'd (#9808) The daemon-lifecycle cleanup-failure test planted a zombie with `sleep 0 & echo $!; exec sleep 600`. dash reaps any exited child after a builtin, so when `sleep 0` exited before `echo` returned, the shell reaped it and `ps -o stat= -p ` failed. The child now reads fd 3 until the helper closes it, which it does only after the shell has become `sleep`. Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> --- packages/app/e2e/support/helpers/daemon-lifecycle.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/app/e2e/support/helpers/daemon-lifecycle.ts b/packages/app/e2e/support/helpers/daemon-lifecycle.ts index c38c0f5f7..dba8a25db 100644 --- a/packages/app/e2e/support/helpers/daemon-lifecycle.ts +++ b/packages/app/e2e/support/helpers/daemon-lifecycle.ts @@ -96,7 +96,7 @@ export async function listTerminalIds(daemon: IsolatedHostDaemon): Promise { +async function psField(pid: number, field: "stat" | "lstart" | "comm"): Promise { const { stdout } = await execFileAsync("ps", ["-o", `${field}=`, "-p", String(pid)], { env: { ...process.env, LC_ALL: "C" }, }); @@ -117,17 +117,22 @@ export interface UnclosableTerminalProgram { export async function plantUnclosableTerminalProgram( daemon: IsolatedHostDaemon, ): Promise { - const parent = spawn("/bin/sh", ["-c", "sleep 0 & echo $!; exec sleep 600"], { - stdio: ["ignore", "pipe", "ignore"], + // The shell reaps any child that has exited whenever it finishes a builtin, so the program + // reads fd 3 until we close it, which happens only once the shell has become `sleep`. + const parent = spawn("/bin/sh", ["-c", "cat <&3 >/dev/null & echo $!; exec sleep 600 3<&-"], { + stdio: ["ignore", "pipe", "ignore", "pipe"], }); parent.unref(); const release = () => { + parent.stdio[3]?.destroy(); if (parent.exitCode === null && parent.signalCode === null) parent.kill("SIGKILL"); }; try { const pid = await new Promise((resolve) => { parent.stdout!.once("data", (chunk: Buffer) => resolve(Number(chunk.toString().trim()))); }); + await expect.poll(() => psField(parent.pid!, "comm")).toMatch(/(^|\/)sleep$/); + parent.stdio[3]!.destroy(); await expect.poll(async () => (await psField(pid, "stat")).startsWith("Z")).toBe(true); const gone = spawn(process.execPath, ["-e", ""], { stdio: "ignore" }); await new Promise((resolve) => gone.once("exit", resolve));