Skip to content

Commit fbb7c72

Browse files
committed
fix(executor-http): avoid shared AbortController in Cloudflare Workers
1 parent a81b8b2 commit fbb7c72

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

.changeset/lovely-coins-dream.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphql-tools/executor-http': patch
3+
---
4+
5+
Avoid shared AbortController instance on CloudflareWorkers because it gives `Cannot perform I/O on behalf of a different request.` error.
6+
This change ensures that the AbortController is only created when not running in a Cloudflare Workers environment.

packages/executors/http/src/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,11 @@ export function buildHTTPExecutor(
189189
request: ExecutionRequest<any, any, any, HTTPExecutorOptions>,
190190
excludeQuery?: boolean,
191191
) => {
192-
disposeCtrl ||= new AbortController();
193-
if (disposeCtrl.signal.aborted) {
192+
// @ts-expect-error Cloudflare Workers doesn't like the shared AbortController
193+
if (!request.cf) {
194+
disposeCtrl ||= new AbortController();
195+
}
196+
if (disposeCtrl?.signal.aborted) {
194197
return createResultForAbort(disposeCtrl.signal.reason);
195198
}
196199
const fetchFn = request.extensions?.fetch ?? options?.fetch ?? defaultFetch;
@@ -264,7 +267,10 @@ export function buildHTTPExecutor(
264267
request.extensions = restExtensions;
265268
}
266269

267-
const signals = [disposeCtrl.signal];
270+
const signals = [];
271+
if (disposeCtrl?.signal) {
272+
signals.push(disposeCtrl.signal);
273+
}
268274
const signalFromRequest = request.signal || request.info?.signal;
269275
if (signalFromRequest) {
270276
if (signalFromRequest.aborted) {
@@ -279,7 +285,7 @@ export function buildHTTPExecutor(
279285
signals.push(subscriptionCtrl.signal);
280286
}
281287

282-
const signal = abortSignalAny(signals);
288+
const signal = signals.length ? abortSignalAny(signals) : undefined;
283289

284290
const upstreamErrorExtensions: UpstreamErrorExtensions = {
285291
request: {

0 commit comments

Comments
 (0)