Skip to content

Commit 27932a8

Browse files
committed
test(process): treat Linux zombies as terminated
1 parent 8bb262d commit 27932a8

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎src/process/supervisor/adapters/child.service-lifecycle.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { spawn } from "node:child_process";
2+
import { readFileSync } from "node:fs";
23
import { writeFile } from "node:fs/promises";
34
import path from "node:path";
45
import { afterEach, describe, expect, it } from "vitest";
@@ -12,10 +13,19 @@ const tempDirs = useAutoCleanupTempDirTracker(afterEach);
1213
function isAlive(pid: number): boolean {
1314
try {
1415
process.kill(pid, 0);
15-
return true;
1616
} catch (error) {
1717
return (error as NodeJS.ErrnoException).code === "EPERM";
1818
}
19+
if (process.platform !== "linux") {
20+
return true;
21+
}
22+
try {
23+
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
24+
// kill(pid, 0) also succeeds for a terminated process awaiting reaping.
25+
return stat.charAt(stat.lastIndexOf(")") + 2) !== "Z";
26+
} catch {
27+
return false;
28+
}
1929
}
2030

2131
async function waitFor(predicate: () => boolean, timeoutMs = 5_000): Promise<void> {

0 commit comments

Comments
 (0)