fix(process): protect unrelated Hopper during cleanup
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { spawn } from "node:child_process";
|
||||
|
||||
/** Start a source-owned decoy whose process title exercises broad Hopper kills. */
|
||||
export const startUnrelatedHopperSentinel = async () => {
|
||||
const environment = { ...process.env };
|
||||
delete environment.REA_PROCESS_RUN_ID;
|
||||
const child = spawn(
|
||||
process.execPath,
|
||||
["-e", "process.title = 'Hopper'; setInterval(() => undefined, 1000)"],
|
||||
{
|
||||
detached: true,
|
||||
stdio: "ignore",
|
||||
env: environment,
|
||||
},
|
||||
);
|
||||
await new Promise((resolve, reject) => {
|
||||
child.once("spawn", resolve);
|
||||
child.once("error", reject);
|
||||
});
|
||||
await new Promise((resolve) => setTimeout(resolve, 25));
|
||||
|
||||
const assertAlive = () => {
|
||||
const pid = child.pid;
|
||||
if (
|
||||
pid === undefined ||
|
||||
child.exitCode !== null ||
|
||||
child.signalCode !== null
|
||||
) {
|
||||
throw new Error(
|
||||
"Unrelated Hopper sentinel was terminated by verification",
|
||||
);
|
||||
}
|
||||
try {
|
||||
process.kill(pid, 0);
|
||||
} catch {
|
||||
throw new Error(
|
||||
"Unrelated Hopper sentinel was terminated by verification",
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const close = async () => {
|
||||
if (child.exitCode !== null || child.signalCode !== null) return;
|
||||
const exited = new Promise((resolve) => child.once("exit", resolve));
|
||||
child.kill("SIGKILL");
|
||||
await exited;
|
||||
};
|
||||
|
||||
const verifyAndClose = async () => {
|
||||
try {
|
||||
assertAlive();
|
||||
return true;
|
||||
} finally {
|
||||
await close();
|
||||
}
|
||||
};
|
||||
|
||||
assertAlive();
|
||||
return { assertAlive, close, verifyAndClose };
|
||||
};
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
} from "./lib/mcp-verifier-results.mjs";
|
||||
import { openAndVerifyLargeFixture } from "./lib/real-hopper-pagination.mjs";
|
||||
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
|
||||
import { startUnrelatedHopperSentinel } from "./lib/unrelated-hopper-sentinel.mjs";
|
||||
const execFileAsync = promisify(execFile);
|
||||
const verifierRun = createVerifierRun();
|
||||
const timeout = 180_000;
|
||||
@@ -283,6 +284,8 @@ transport.stderr?.on("data", (chunk) => {
|
||||
if (stderrBytes <= 16_384) stderrChunks.push(chunk.toString("utf8"));
|
||||
});
|
||||
const client = new Client({ name: "real-hopper-verifier", version: "1.0.0" });
|
||||
const unrelatedHopper = await startUnrelatedHopperSentinel();
|
||||
let unrelatedHopperSurvived = false;
|
||||
let summary;
|
||||
|
||||
try {
|
||||
@@ -458,6 +461,7 @@ try {
|
||||
await transport.close();
|
||||
} finally {
|
||||
clearInterval(keepAlive);
|
||||
unrelatedHopperSurvived = await unrelatedHopper.verifyAndClose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -487,7 +491,7 @@ if (summary === undefined)
|
||||
const completedVerifierRun = await completeVerifierRun(verifierRun);
|
||||
await new Promise((resolve, reject) => {
|
||||
process.stdout.write(
|
||||
`${JSON.stringify({ verifier_run: completedVerifierRun, ...summary, cleanShutdown: true }, null, 2)}\n`,
|
||||
`${JSON.stringify({ verifier_run: completedVerifierRun, ...summary, unrelatedHopperSurvived, cleanShutdown: true }, null, 2)}\n`,
|
||||
(cause) => {
|
||||
if (cause) reject(cause);
|
||||
else resolve();
|
||||
|
||||
Reference in New Issue
Block a user