From 58a5817da692bbb3d9efaa95857d3515c36de7a5 Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Mon, 30 Mar 2026 20:26:50 +0300 Subject: [PATCH] refactor(executor): replace internal abort signal with lightweight abort state --- src/execution/Executor.ts | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/execution/Executor.ts b/src/execution/Executor.ts index dc83e62f37..faf75b387b 100644 --- a/src/execution/Executor.ts +++ b/src/execution/Executor.ts @@ -43,7 +43,7 @@ import { } from '../type/definition.js'; import type { GraphQLSchema } from '../type/schema.js'; -import { cancellablePromise } from './cancellablePromise.js'; +import { withCancellation } from './cancellablePromise.js'; import type { DeferUsage, FieldDetailsList, @@ -223,8 +223,9 @@ export class Executor< > { validatedExecutionArgs: ValidatedExecutionArgs; aborted: boolean; + abortReason: unknown; collectedErrors: CollectedErrors; - internalAbortController: AbortController; + abortResultPromise: ((reason?: unknown) => void) | undefined; resolverAbortController: AbortController | undefined; sharedResolverAbortSignal: AbortSignal; @@ -234,8 +235,8 @@ export class Executor< ) { this.validatedExecutionArgs = validatedExecutionArgs; this.aborted = false; + this.abortReason = new Error('This operation was aborted'); this.collectedErrors = new CollectedErrors(); - this.internalAbortController = new AbortController(); if (sharedResolverAbortSignal === undefined) { this.resolverAbortController = new AbortController(); @@ -318,7 +319,13 @@ export class Executor< return this.buildResponse(null); }, ); - return cancellablePromise(promise, this.internalAbortController.signal); + const { promise: cancellablePromise, abort: abortResultPromise } = + withCancellation(promise); + this.abortResultPromise = abortResultPromise; + if (this.aborted) { + abortResultPromise(this.abortReason); + } + return cancellablePromise; } maybeRemoveExternalAbortListener(); return this.buildResponse(result); @@ -330,7 +337,9 @@ export class Executor< } throwIfAborted(): void { - this.internalAbortController.signal.throwIfAborted(); + if (this.aborted) { + throw this.abortReason; + } } abort(reason?: unknown): PromiseOrValue { @@ -338,13 +347,16 @@ export class Executor< return; } this.aborted = true; - this.internalAbortController.abort(reason); - this.resolverAbortController?.abort(reason); + if (reason !== undefined) { + this.abortReason = reason; + } + this.abortResultPromise?.(this.abortReason); + this.resolverAbortController?.abort(this.abortReason); } finish(): void { - this.aborted = true; this.throwIfAborted(); + this.aborted = true; } /**