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(server): use the recommended connection handler from @fastify/websocket to avoid triggering stream backpressure (#5530) #5532

Merged
merged 2 commits into from
Mar 2, 2024

Conversation

mat-sz
Copy link
Contributor

@mat-sz mat-sz commented Mar 2, 2024

Closes #5530

🎯 Changes

I've moved connection event handler creation into a separate function to allow for it being used directly inside of the @fastify/websocket connection callback.

Also, I deliberately left prefix handling in applyWSSHandler, so we can leave routing to fastify itself.

For future consideration - might be worth using something in line of the following to stay compatible with future versions of @fastify/websocket (if my changes get approved) alongside with backwards compatibility:

    fastify.get(prefix ?? '/', { websocket: true }, (connection, req) => {
      onConnection('socket' in connection ? connection.socket : connection, req.raw);
    });

There's a chance they might end up just exposing the raw WebSocket object on their end from the handler, but this isn't guaranteed to happen.

Update: I've submitted a PR to @fastify/websocket as well, might be worth checking out with regards to compatibility: fastify/fastify-websocket#290

✅ Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

@mat-sz mat-sz requested a review from a team as a code owner March 2, 2024 18:31
Copy link

vercel bot commented Mar 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
trpc-next-app-dir ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 2, 2024 6:46pm
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 2, 2024 6:46pm

Copy link

vercel bot commented Mar 2, 2024

@mat-sz is attempting to deploy a commit to the trpc Team on Vercel.

A member of the Team first needs to authorize it.

Comment on lines +541 to +542
// https://github.com/trpc/trpc/issues/5530
describe('issue #5530 - cannot receive new WebSocket messages after receiving 16 kB', () => {
Copy link
Member

Choose a reason for hiding this comment

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

awesome, thanks

@KATT KATT merged commit 1724978 into trpc:next Mar 2, 2024
34 of 36 checks passed
Copy link

github-actions bot commented Mar 4, 2024

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants