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

The RPC request coalescer now throws exceptions whether you configure it with an AbortSignal or not #2910

Merged
merged 3 commits into from
Jul 22, 2024

Conversation

Jac0xb
Copy link
Contributor

@Jac0xb Jac0xb commented Jul 4, 2024

Summary

When an AbortSignal was supplied to the RPC request coalescer, it would fail to attach a rejection handler to the shim promise returned to the app.

Test Plan

cd packages/rpc/
pnpm turbo test:unit:node test:unit:browser

Copy link

changeset-bot bot commented Jul 4, 2024

🦋 Changeset detected

Latest commit: 74bbe34

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mergify mergify bot added the community label Jul 4, 2024
@mergify mergify bot requested a review from a team July 4, 2024 02:48
@Jac0xb
Copy link
Contributor Author

Jac0xb commented Jul 4, 2024

Open to other solutions just want to surface this

Copy link
Collaborator

@steveluscher steveluscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's almost certainly this:

            return await new Promise<TResponse>((resolve, reject) => {
                const handleAbort = (e: AbortSignalEventMap['abort']) => {
                    signal.removeEventListener('abort', handleAbort);
                    coalescedRequest.numConsumers -= 1;
                    Promise.resolve().then(() => {
                        if (coalescedRequest.numConsumers === 0) {
                            const abortController = coalescedRequest.abortController;
                            abortController.abort((EXPLICIT_ABORT_TOKEN ||= createExplicitAbortToken()));
                        }
                    });
                    reject((e.target as AbortSignal).reason);
                };
                signal.addEventListener('abort', handleAbort);
                responsePromise.then(resolve).finally(() => {
                    signal.removeEventListener('abort', handleAbort);
                }); // <==== this is missing a `catch(reject)`
            });

When there's an abortSignal we drop into that shim, and responsePromise's failure case is not folded into the shim promise's reject, so it just explodes all over the event loop.

I'm happy to fix this, but if you want to fix it, it's gonna need a realllllly good failing test!

@@ -59,7 +59,7 @@ export function getRpcTransportWithRequestCoalescing<TTransport extends RpcTrans
}
throw e;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, this can't possibly throw synchronously because transport() is awaited.

@github-actions github-actions bot added the stale label Jul 18, 2024
@steveluscher steveluscher changed the title Unhandled rpc request coalescer promise crashing node. The RPC request coalescer now throws exceptions whether you configure it with an AbortSignal or not Jul 22, 2024
@steveluscher steveluscher added the automerge Merge this Pull Request automatically once CI passes label Jul 22, 2024
@mergify mergify bot merged commit 42a70f4 into solana-labs:master Jul 22, 2024
6 checks passed
@github-actions github-actions bot mentioned this pull request Jul 22, 2024
Copy link
Contributor

🎉 This PR is included in version 1.95.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link
Contributor

Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
automerge Merge this Pull Request automatically once CI passes community released stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants