proc: a Linux zombie no longer holds a lock (#1198)

yetihan (#1198): a lock whose owner is a Linux zombie was held for
good. process.kill(pid, 0) succeeds on a zombie, so 15 packages' lock
and liveness checks counted an exited, unreaped owner as alive.

- scripts/proc.mjs: processStatus(pid) is dead on ESRCH, and on Linux
  also when /proc/<pid>/stat says Z or X; EPERM is "permission", any
  other error "unknown". processAlive / processExists keep each
  caller's old EPERM and unknown-error meaning.
- scripts/sync-proc.mjs copies it into each package (--check in the
  tests); every package's own check keeps its old semantics, now with
  zombies dead. agent-console's daemon bundle and window-warmup's dist
  are rebuilt.
- 15 packages bumped.

Review run at 28ef6622 (mote, HOME=$(mktemp -d)):
- node scripts/sync-proc.mjs --check: ok.
- bun test (whole repo): 8934 pass, 0 fail.
- bun scripts/check.mjs: every package ok.
- window-warmup's build reproduces its dist/plugin.js byte for byte.
  agent-console's bundle diff read line by line: the proc module plus
  esbuild's renumbered imports, nothing else (esbuild isn't installed
  on mote, so it wasn't rebuilt there).
- Real zombie on Linux (WSL, magpie-desktop): a bash child left
  unreaped by an exec'd sleep, /proc stat "Z": the old kill(0) check
  says alive, processStatus says dead; the running process says alive.

Not tried: each package's lock contention end to end.
This commit is contained in:
zhou.han
2026-11-16 12:19:09 +08:00
committed by GitHub
parent 0b0b180957
commit 9e86a2c7b7
63 changed files with 1391 additions and 158 deletions
+13 -8
View File
@@ -1,16 +1,21 @@
// Small process/environment helpers: cross-platform pid liveness, PATH completion.
import { delimiter } from "node:path";
import { extraBinDirs } from "../../../lib/pathscan.mjs";
import { processAlive } from "../../../lib/proc.mjs";
type ProcessAliveDeps = {
platform?: NodeJS.Platform;
procRoot?: string;
readFile?: (file: string) => string;
};
/** kill(pid, 0): ESRCH = gone; EPERM = exists but we may not signal it (common on Windows across sessions / elevated processes), counts as alive. */
export function pidAlive(pid: number, kill: (pid: number, sig: 0) => unknown = (p, s) => process.kill(p, s)): boolean {
if (!Number.isInteger(pid) || pid <= 0) return false;
try {
kill(pid, 0);
return true;
} catch (e) {
return (e as NodeJS.ErrnoException)?.code === "EPERM";
}
export function pidAlive(
pid: number,
kill: (pid: number, sig: 0) => unknown = (p, s) => process.kill(p, s),
deps: ProcessAliveDeps = {},
): boolean {
return processAlive(pid, { ...deps, kill });
}
/** Append nodeDir and common CLI install directories to the end of PATH (deduped; case-insensitive on Windows). Returns the new PATH string. */