refactor(providers): share queued close attempts (#14563)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-11-25 15:54:04 +00:00
1 parent 2f5dc7b27c
commit dcce28e284
6 files changed
+62 -63

No files matched your search

+8 -15
View File
@@ -1,3 +1,4 @@
import { QueuedProviderClose } from "../../providers/QueuedProviderClose.js";
import { snapshotEnvironment } from "../../process/snapshotEnvironment.js";
import {
HOST_PLATFORM,
@@ -63,8 +64,7 @@ interface PendingRecoveryCleanup {
export class WakaruProvider implements JavaScriptRecoveryPort {
readonly #resources = new ArtifactResourceScope();
#tail: Promise<void> = Promise.resolve();
#closing = false;
#closePromise: Promise<void> | undefined;
readonly #closeState = new QueuedProviderClose();
#pendingCleanup:
| {
readonly resources: PendingRecoveryCleanup;
@@ -86,9 +86,12 @@ export class WakaruProvider implements JavaScriptRecoveryPort {
input: JavaScriptRecoveryInput,
options?: ExecutionOptions,
): Promise<Result<AnalysisExecution, AnalysisError>> {
if (this.#closing) return Promise.resolve(err(this.#closedError()));
if (this.#closeState.requested)
return Promise.resolve(err(this.#closedError()));
const operation = this.#tail.then(() =>
this.#closing ? err(this.#closedError()) : this.#recover(input, options),
this.#closeState.requested
? err(this.#closedError())
: this.#recover(input, options),
);
this.#tail = operation.then(
() => undefined,
@@ -361,17 +364,7 @@ export class WakaruProvider implements JavaScriptRecoveryPort {
}
async close(): Promise<void> {
this.#closing = true;
this.#closePromise ??= this.#tail
.then(async () => {
const failure = await this.#retire();
if (failure !== undefined) throw failure;
})
.catch((cause: unknown) => {
this.#closePromise = undefined;
throw cause;
});
return this.#closePromise;
return this.#closeState.closeAfter(this.#tail, () => this.#retire());
}
async #retire(): Promise<ProviderCleanupError | undefined> {
+5 -15
View File
@@ -1,3 +1,4 @@
import { QueuedProviderClose } from "../../providers/QueuedProviderClose.js";
import {
selectedSourceMapLimits,
localSourceMapLimitsSchema,
@@ -35,8 +36,7 @@ const OPERATION = "trace_web_source_location";
/** Integrate the pinned upstream codec through an independently bounded owned process. */
export class SourceMapDecoder implements WebSourceMapPort {
#tail: Promise<void> = Promise.resolve();
#closing = false;
#closePromise: Promise<void> | undefined;
readonly #closeState = new QueuedProviderClose();
#pendingCleanup: SourceMapCleanupOwner | undefined;
constructor(readonly dependencies: SourceMapDecoderDependencies = {}) {}
@@ -45,7 +45,7 @@ export class SourceMapDecoder implements WebSourceMapPort {
input: Parameters<WebSourceMapPort["trace"]>[0],
options?: ExecutionOptions,
): Promise<Result<WebSourceMapReport, AnalysisError>> {
if (this.#closing)
if (this.#closeState.requested)
return err(
new AnalysisCapabilityUnavailableError(
"source-map-decoder",
@@ -66,7 +66,7 @@ export class SourceMapDecoder implements WebSourceMapPort {
return err(cancelledBy(OPERATION, ready));
}
try {
return this.#closing
return this.#closeState.requested
? err(
new AnalysisCapabilityUnavailableError(
"source-map-decoder",
@@ -150,17 +150,7 @@ export class SourceMapDecoder implements WebSourceMapPort {
}
async close(): Promise<void> {
this.#closing = true;
this.#closePromise ??= this.#tail
.then(async () => {
const failure = await this.#retryCleanup();
if (failure !== undefined) throw failure;
})
.catch((cause: unknown) => {
this.#closePromise = undefined;
throw cause;
});
return this.#closePromise;
return this.#closeState.closeAfter(this.#tail, () => this.#retryCleanup());
}
async #retryCleanup(): Promise<AnalysisError | undefined> {