refactor(process): recognise SQLite, WABT and Flutter aborts through the signal owner (#10975)

This commit is contained in:
morluto authored and GitHub committed 2026-11-15 17:17:28 +08:00
1 parent 97a5460bd1
commit b527eccd48
6 files changed
+78 -19

No files matched your search

@@ -167,7 +167,6 @@
"src/server/registerSessionRecordTools.ts": 1,
"src/server/runDerivedOperation.ts": 2,
"src/signals/SigrokRecordingProvider.ts": 1,
"src/sqlite/SqliteDatabaseFailures.ts": 1,
"src/sqlite/SqliteDatabaseProvider.ts": 4,
"src/sqlite/SqliteDatabaseWorkerExecution.ts": 1
},
@@ -387,5 +386,12 @@
},
"wall-clock-deadline": {
"src/browser/PlaywrightScenarioRequest.ts": 1
},
"abort-error-name": {
"src/evm/EvmoleInterfaceProvider.ts": 1,
"src/ida/IdaBusyHealth.ts": 1,
"src/process/ExecFileOutput.ts": 1,
"src/server/http/listenHttpServer.ts": 1,
"src/sqlite/SqliteDatabaseFailures.ts": 1
}
}
+10
View File
@@ -234,6 +234,16 @@ checkCounted(
["src/domain/analysisErrorCore.ts"],
);
// Whether an abort error is a signal's own cancellation is decided by the
// signal owner; a name comparison alone accepts another signal's abort.
checkCounted(
"AbortError name comparison (use isAbortOf or isAbortWithReason from src/process/SignalAbort)",
"abort-error-name",
files,
/\.name\s*===\s*["']AbortError["']/gu,
["src/process/SignalAbort.ts"],
);
// A deadline is a monotonic budget owned by `Deadline` in src/domain/deadline;
// a wall-clock sum moves with clock changes and has no finalize phase. The
// remaining copy converts a monotonic budget for a browser page, which can
+2 -5
View File
@@ -42,6 +42,7 @@ import {
cancelledBy,
carriedReason,
} from "../domain/analysisErrorCore.js";
import { isAbortWithReason } from "../process/SignalAbort.js";
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
import { fixedAllowanceOptions as flutterBudget } from "../domain/fixedAllowanceRemediation.js";
import {
@@ -113,11 +114,7 @@ const sha256File = async (
}
return hash.digest("hex");
} catch (cause) {
if (
cause instanceof Error &&
cause.name === "AbortError" &&
cause.cause === marker
)
if (isAbortWithReason(cause, marker))
throw cancelledBy(operation, carriedReason(signal?.reason));
throw cause;
} finally {
+50
View File
@@ -0,0 +1,50 @@
import { setTimeout as delay } from "node:timers/promises";
import { expect, it } from "vitest";
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
import { classifyProviderFailure } from "../providers/classifyProviderFailure.js";
import { sqliteDatabaseDialect } from "./SqliteDatabaseFailures.js";
/** The abort error Node's signal-aware I/O rejects with for `signal`. */
const nodeAbortError = (signal: AbortSignal): Promise<unknown> =>
delay(1, undefined, { signal }).then(
() => {
throw new Error("Expected the aborted delay to reject");
},
(cause: unknown) => cause,
);
it.each([
["an object", { source: "caller" }],
["NaN", Number.NaN],
])(
"reports the caller's own abort with its reason when the reason is %s",
async (_label, reason) => {
const caller = new AbortController();
caller.abort(reason);
const failure = classifyProviderFailure(
await nodeAbortError(caller.signal),
sqliteDatabaseDialect("/selected.db", "artifact-read", caller.signal),
);
expect(failure).toBeInstanceOf(AnalysisCancelledError);
expect(Object.is(failure.cause, reason)).toBe(true);
},
);
it("keeps another signal's abort error as the cancellation's cause", async () => {
const caller = new AbortController();
caller.abort({ source: "caller" });
const other = new AbortController();
other.abort({ source: "another owner" });
const foreign = await nodeAbortError(other.signal);
const failure = classifyProviderFailure(
foreign,
sqliteDatabaseDialect("/selected.db", "artifact-read", caller.signal),
);
expect(failure).toBeInstanceOf(AnalysisCancelledError);
expect(failure.cause).toBe(foreign);
});
+7 -7
View File
@@ -17,8 +17,10 @@ import type { JsonValue } from "../domain/jsonValue.js";
import {
AnalysisArtifactChangedError,
AnalysisCapabilityUnavailableError,
AnalysisCancelledError,
cancelledBy,
carriedReason,
} from "../domain/analysisErrorCore.js";
import { isAbortOf } from "../process/SignalAbort.js";
import { fixedAllowanceOptions } from "../domain/fixedAllowanceRemediation.js";
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
@@ -129,13 +131,11 @@ export const sqliteDatabaseDialect = (
? undefined
: stableArtifactInputFailure(cause, OPERATION);
}
// This signal's own abort carries its reason; another abort error
// is still a cancellation, reported as itself.
if (isAbortOf(cause, signal)) return cancelledBy(OPERATION, signal);
if (cause instanceof Error && cause.name === "AbortError")
return new AnalysisCancelledError(OPERATION, {
cause:
signal?.aborted === true && cause.cause === signal.reason
? signal.reason
: cause,
});
return cancelledBy(OPERATION, carriedReason(cause));
// Windows reports a sharing violation as EBUSY: another process holds
// the file without read sharing. The unchanged request succeeds once
// that process releases it. Name the member of the file set that was
+2 -6
View File
@@ -35,6 +35,7 @@ import {
AnalysisInputError,
AnalysisOutputError,
} from "../domain/analysisErrorCore.js";
import { isAbortOf } from "../process/SignalAbort.js";
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js";
import { analysisErrorWithCancellation } from "../domain/analysisErrorCancellation.js";
@@ -520,12 +521,7 @@ export class WabtArtifactProvider implements WasmArtifactPort {
}).catch((cause: unknown) => {
// Node rejects a write this signal aborted with an envelope that
// carries the signal's own reason; any other failure stays itself.
if (
isAborted(signal) &&
cause instanceof Error &&
cause.cause === signal.reason
)
throw cancelledBy(OPERATION, signal);
if (isAbortOf(cause, signal)) throw cancelledBy(OPERATION, signal);
throw cause;
});
snapshotHash = selected.sha256;