Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in Node <21 that prevented the normal operation of the request coalescer #2326

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading