refactor(process): inherit cleanup ownership for debugger cancellation (#12537)

This commit is contained in:
RRFZ authored and GitHub committed 2026-11-19 17:28:02 -05:00
1 parent 3b1527a56f
commit fa9abed521
3 files changed
+34 -4

No files matched your search

@@ -33,7 +33,6 @@
"src/pcap/PcapProvider.ts": 5,
"src/pcap/PcapSnapshot.ts": 1,
"src/process/ArtifactAnalysisResources.ts": 1,
"src/process/OwnedDebuggerSessionRegistry.ts": 1,
"src/process/capture/ProcessCaptureError.ts": 3,
"src/providers/AnalysisClientFailure.ts": 1,
"src/sqlite/SqliteDatabaseProvider.ts": 8
@@ -0,0 +1,30 @@
import { expect, it } from "vitest";
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
import { cancelledWithCallerReason } from "./OwnedDebuggerSessionRegistry.js";
it("preserves the caller's reason while a retained cancellation waits for release", () => {
const reason = new Error("caller stopped waiting");
const previous = new AnalysisCancelledError("start", {
cleanup: {
reason: "session still closing",
resources: ["session"],
},
});
const claim = { cleanupReleased: false };
previous.bindCleanupReleaseClaim(claim);
const current = cancelledWithCallerReason(
"close",
AbortSignal.abort(reason),
previous,
);
expect(current.cause).toBe(reason);
expect(current.cleanupPrimary).toBe(previous);
expect(current.cleanupIncomplete).toBe(true);
expect(current.cleanupResources).toEqual(["session"]);
claim.cleanupReleased = true;
expect(current.cleanupIncomplete).toBe(false);
expect(
cancelledWithCallerReason("close", AbortSignal.abort(reason))
.cleanupIncomplete,
).toBe(false);
});
+4 -3
View File
@@ -1,3 +1,4 @@
import { withInheritedCleanupOwnership } from "../domain/analysisErrorCleanup.js";
import type {
AnalysisError,
AnalysisErrorOptions,
@@ -294,7 +295,7 @@ export const cancelledWithCallerReason = (
? {}
: { partialObservation: previous.partialObservation }),
});
if (previous?.cleanupIncomplete)
cancellation.bindCleanupDependencies([previous]);
return cancellation;
return previous === undefined
? cancellation
: withInheritedCleanupOwnership(cancellation, previous);
};