fix(source-maps): cancel requests waiting for decoder admission (#13844)

Co-authored-by: hhang <169027046+xu91102@users.noreply.github.com>
This commit is contained in:
hhang
2026-11-22 21:07:49 -05:00
committed by GitHub
parent d8f34c530d
commit 72eede75d1
2 changed files with 90 additions and 17 deletions
@@ -1,4 +1,5 @@
import { access } from "node:fs/promises";
import { setImmediate as nextTurn } from "node:timers/promises";
import { expect, it } from "vitest";
import { ProviderCleanupError } from "../../domain/providerCleanupError.js";
import { DarwinProcessOwnershipInspectionError } from "../../process/DarwinProcessRunTokenReader.js";
@@ -18,6 +19,7 @@ import {
webSourceLocationFixture,
} from "../../../tests/fixtures/webSourceLocation.js";
import { releaseOwnedCleanup } from "../../../tests/support/cleanupRelease.js";
import { createDeferred } from "../../../tests/fixtures/binarySession.js";
const fixture = webSourceLocationFixture();
const input = {
@@ -39,6 +41,66 @@ it("preserves the exact caller reason before source-map admission", async () =>
expect(response.error.cause).toBe(reason);
});
it("cancels queued source-map work while the active request keeps its runtime", async () => {
const entered = createDeferred<void>();
const release = createDeferred<void>();
const roots: string[] = [];
const decoder = new SourceMapDecoder({
async createRuntime() {
const root = await PrivateRuntimeRoot.create({
prefix: "rea-source-map-queued-test-",
});
roots.push(root.path);
if (roots.length === 1) {
entered.resolve();
await release.promise;
}
return root;
},
launcher: (options) =>
spawnOwnedProviderProcess({
...options,
arguments: ["-e", "process.exit(7)"],
}),
});
const active = decoder.trace(input);
try {
await entered.promise;
const controller = new AbortController();
const reason = { caller: "cancel the waiting source-map request" };
const queued = decoder.trace(input, { signal: controller.signal });
const following = decoder.trace(input);
controller.abort(reason);
const result = await Promise.race([
queued,
nextTurn("still queued" as const),
]);
expect(result).not.toBe("still queued");
if (result === "still queued" || result.ok)
throw new Error("Expected cancellation before decoder admission");
expect(result.error).toBeInstanceOf(AnalysisCancelledError);
expect(result.error.cause).toBe(reason);
expect(result.error.cleanupIncomplete).toBe(false);
expect(roots).toHaveLength(1);
await expect(access(roots[0]!)).resolves.toBeUndefined();
release.resolve();
const exited = {
ok: false,
error: { _tag: "ProviderAdapterError", diagnostics: { exit_code: 7 } },
};
await expect(active).resolves.toMatchObject(exited);
await expect(following).resolves.toMatchObject(exited);
expect(roots).toHaveLength(2);
for (const path of roots)
await expect(access(path)).rejects.toMatchObject({ code: "ENOENT" });
} finally {
release.resolve();
await decoder.close();
}
});
it("retains physical failure and late cancellation through cleanup failure and retry", async () => {
const root = await PrivateRuntimeRoot.create({
prefix: "rea-source-map-cleanup-retry-test-",