fix(rpc): reject pending requests on child process exit

closes #4764
This commit is contained in:
Armin Ronacher
2026-05-25 00:40:07 +02:00
parent ce0e801d8e
commit e007fcd0d2
3 changed files with 104 additions and 8 deletions

View File

@@ -0,0 +1,38 @@
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, test } from "vitest";
import { RpcClient } from "../src/modes/rpc/rpc-client.ts";
const tempDirs: string[] = [];
function writeChildScript(contents: string): string {
const dir = mkdtempSync(join(tmpdir(), "pi-rpc-client-exit-"));
tempDirs.push(dir);
const path = join(dir, "child.mjs");
writeFileSync(path, contents);
return path;
}
afterEach(() => {
for (const dir of tempDirs.splice(0)) {
rmSync(dir, { recursive: true, force: true });
}
});
describe("RpcClient child process failures", () => {
test("rejects an in-flight request when the child process exits", async () => {
const client = new RpcClient({
cliPath: writeChildScript(`
process.stdin.once("data", () => {
process.exit(43);
});
process.stdin.resume();
`),
});
await client.start();
await expect(client.getCommands()).rejects.toThrow(/Agent process exited \(code=43 signal=null\)/);
});
});