Skip to content

Commit 1cae508

Browse files
committed
test(ssh): zombie-reap launch test no longer races the shell
The test killed the background child as soon as sh printed its pid. If the kill landed before sh exec'd, dash's SIGCHLD handling reaped the child, so no zombie was left and ps printed nothing. Kill the child only after sh has exec'd into node, which never reaps an inherited child, and print its pid once SIGCHLD confirms it is a zombie.
1 parent 81493ef commit 1cae508

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎packages/ssh/src/tunnel.test.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,15 +1210,27 @@ server.listen(Number(flag("--port")), "127.0.0.1", () => {
12101210

12111211
// A crashed server whose parent never reaps it stays a zombie, which
12121212
// kill -0 still reports. Its pid file and runtime record keep naming it.
1213+
// The child is killed only after sh has exec'd into node, which never
1214+
// reaps it (sh would), and its pid is printed once SIGCHLD confirms the
1215+
// zombie exists.
12131216
const parent = yield* spawner.spawn(
1214-
ChildProcess.make("sh", ["-c", "sleep 600 & echo $!; exec sleep 600"]),
1217+
ChildProcess.make("sh", [
1218+
"-c",
1219+
'sleep 600 & exec node -e "$1" "$!"',
1220+
"sh",
1221+
[
1222+
"const child = Number(process.argv[1]);",
1223+
'process.on("SIGCHLD", () => console.log(child));',
1224+
'process.kill(child, "SIGKILL");',
1225+
"setInterval(() => {}, 1 << 30);",
1226+
].join("\n"),
1227+
]),
12151228
);
12161229
const zombie = Number(
12171230
Option.getOrThrow(
12181231
yield* parent.stdout.pipe(Stream.decodeText(), Stream.splitLines, Stream.runHead),
12191232
),
12201233
);
1221-
process.kill(zombie, "SIGKILL");
12221234
assert.include((yield* runScript(home, ["-c", `ps -o stat= -p ${zombie}`])).stdout, "Z");
12231235
yield* fs.writeFileString(`${stateDir}/pid`, `${zombie}\n`);
12241236
yield* fs.writeFileString(

0 commit comments

Comments
 (0)