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.
30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import { alive } from "./lock.mjs";
|
|
|
|
const err = (code) => () => {
|
|
throw Object.assign(new Error(code), { code });
|
|
};
|
|
const deps = (stat, killImpl = () => {}) => ({
|
|
platform: "linux",
|
|
procRoot: "/fake-proc",
|
|
readFile: () => {
|
|
if (stat === undefined) throw Object.assign(new Error("EACCES"), { code: "EACCES" });
|
|
return stat;
|
|
},
|
|
kill: killImpl,
|
|
});
|
|
|
|
test("alive keeps lock ownership semantics while rejecting zombies", () => {
|
|
assert.equal(alive(0), true);
|
|
assert.equal(alive(123, deps("123 (comm)) Z 1")), false);
|
|
assert.equal(alive(123, deps("123 (comm)) X 1")), false);
|
|
assert.equal(alive(123, deps("123 (comm) R 1")), true);
|
|
assert.equal(alive(123, deps(undefined, err("EPERM"))), true);
|
|
assert.equal(alive(123, deps("123 (comm)) Z 1", err("EPERM"))), false);
|
|
assert.equal(alive(123, deps(undefined, err("ESRCH"))), false);
|
|
|
|
const failure = Object.assign(new Error("EIO"), { code: "EIO" });
|
|
assert.throws(() => alive(123, deps(undefined, () => { throw failure; })), (error) => error === failure);
|
|
});
|