Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Fix a bug in Node <21 that prevented the normal operation of the requ…
Browse files Browse the repository at this point in the history
…est coalescer (#2326)
  • Loading branch information
steveluscher authored Mar 15, 2024
1 parent bf1f7bd commit 0d4a1f9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/rpc/src/rpc-request-coalescer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ type CoalescedRequest = {

type GetDeduplicationKeyFn = (payload: unknown) => string | undefined;

const EXPLICIT_ABORT_TOKEN = Symbol(
__DEV__
? 'This symbol is thrown from the request that underlies a series of coalesced requests ' +
'when the last request in that series aborts'
: undefined,
);
// This used to be a `Symbol()`, but there's a bug in Node <21 where the `undici` library passes
// the `reason` property of the `AbortSignal` straight to `Error.captureStackTrace()` without first
// typechecking it. `Error.captureStackTrace()` fatals when given a `Symbol`.
// See https://github.com/nodejs/undici/pull/2597
const EXPLICIT_ABORT_TOKEN = __DEV__
? {
EXPLICIT_ABORT_TOKEN:
'This object is thrown from the request that underlies a series of coalesced ' +
'requests when the last request in that series aborts',
}
: {};

export function getRpcTransportWithRequestCoalescing<TTransport extends RpcTransport>(
transport: TTransport,
Expand Down

0 comments on commit 0d4a1f9

Please sign in to comment.