fix: address Copilot review round 4 (#2339)
Handle SIGQUIT (Ctrl-\) on the same tree-shutdown path as SIGINT, SIGTERM and SIGHUP. The gate runs in its own process group, so a signal the wrapper does not handle ends the wrapper alone and orphans the gate behind a lease that then goes stale under it. The signal test is parametrized over SIGTERM (143) and SIGQUIT (131). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PsmUAZ6aLUAFqenjJKSSRp Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
d3e5432532
commit
17e85a8745
2 changed files with 66 additions and 51 deletions
|
|
@ -468,7 +468,11 @@ export async function runUnderLease({
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const signals = ["SIGINT", "SIGTERM", "SIGHUP"];
|
// Every signal a terminal or a supervisor sends to end a run: Ctrl-C, a
|
||||||
|
// plain kill, a closed terminal, and Ctrl-\ — the child is in its own
|
||||||
|
// group, so any of these left unhandled would end this process and
|
||||||
|
// orphan the gate behind a lease that then goes stale under it.
|
||||||
|
const signals = ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"];
|
||||||
let stoppedBy = null;
|
let stoppedBy = null;
|
||||||
let escalation = null;
|
let escalation = null;
|
||||||
let handlers = [];
|
let handlers = [];
|
||||||
|
|
|
||||||
|
|
@ -397,7 +397,15 @@ test("main: no command is a usage error", async () => {
|
||||||
assert.match(lines.join("\n"), /usage:/);
|
assert.match(lines.join("\n"), /usage:/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("a signal to the wrapper stops the whole tree, releases the lease and exits 128+signal", async () => {
|
// Ctrl-C and a plain kill are the obvious ones; Ctrl-\ (SIGQUIT) is the one
|
||||||
|
// that was missed (Copilot), and it matters for the same reason: the child
|
||||||
|
// is in its own process group, so a signal the wrapper does not handle ends
|
||||||
|
// the wrapper alone and orphans the gate.
|
||||||
|
for (const [signal, code] of [
|
||||||
|
["SIGTERM", 143],
|
||||||
|
["SIGQUIT", 131],
|
||||||
|
]) {
|
||||||
|
test(`${signal} to the wrapper stops the whole tree, releases the lease and exits ${code}`, async () => {
|
||||||
const dir = freshDir();
|
const dir = freshDir();
|
||||||
const pidFile = join(dir, "grandchild.pid");
|
const pidFile = join(dir, "grandchild.pid");
|
||||||
// The gate stand-in: starts a descendant of its own (as `npm run` does,
|
// The gate stand-in: starts a descendant of its own (as `npm run` does,
|
||||||
|
|
@ -433,18 +441,21 @@ test("a signal to the wrapper stops the whole tree, releases the lease and exits
|
||||||
} finally {
|
} finally {
|
||||||
// On every path — a failed setup assertion included — the wrapper is
|
// On every path — a failed setup assertion included — the wrapper is
|
||||||
// told to stop, so an idle grandchild can never outlive the suite.
|
// told to stop, so an idle grandchild can never outlive the suite.
|
||||||
wrapper.kill("SIGTERM");
|
wrapper.kill(signal);
|
||||||
}
|
}
|
||||||
const outcome = await exited;
|
const outcome = await exited;
|
||||||
assert.deepEqual(outcome, { code: 143, signal: null }, stderr);
|
assert.deepEqual(outcome, { code, signal: null }, stderr);
|
||||||
for (const pid of tree)
|
for (const pid of tree)
|
||||||
await waitFor(() => !isAlive(pid)).catch(() => {
|
await waitFor(() => !isAlive(pid)).catch(() => {
|
||||||
process.kill(pid, "SIGKILL");
|
process.kill(pid, "SIGKILL");
|
||||||
assert.fail(`pid ${pid} outlived the wrapper — the tree was not stopped`);
|
assert.fail(
|
||||||
|
`pid ${pid} outlived the wrapper — the tree was not stopped`,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
assert.ok(
|
assert.ok(
|
||||||
!existsSync(lockPathOf(dir)),
|
!existsSync(lockPathOf(dir)),
|
||||||
"the lease was released on the way out",
|
"the lease was released on the way out",
|
||||||
);
|
);
|
||||||
assert.match(stderr, /received SIGTERM; stopping the gate/);
|
assert.match(stderr, new RegExp(`received ${signal}; stopping the gate`));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue