WebSocket connection hangs after significant amount of data passed through the connection.
Hey!
I've been really enjoying using tRPC on my latest project, but have gotten stuck getting websockets to work properly these last few days.
I'm able to establish a connection and successfully pass data back and forth between the client and server, but after a certain amount of data has been passed over the connection, the server stops responding without any error (the connection remains alive).
There's no clear pattern as to why, besides it depending on the amount of data. I can pass 10 very large messages before it hangs, or 100+ smaller messages, and get the same result.
I've tried going around tRPC and establishing a direct websocket connection with the server (I'm using tRPC + Fastify), and don't encounter this issue, so it seems to be something with tRPC.
Let me know if there's any more information I can provide to help you help me π Thank you!!
4 Replies
Unknown Userβ’2y ago
Message Not Public
Sign In & Join Server To View
So I ended up resolving this issue with this fix:
1. After registering the
fastifyWebsocketPlugin
, I added the attached block of code that told fastify to listen for all websocket messages on a different prefix (namely, /ws
while all of my other routes are /api
), without actually doing anything with them.
2. Once I did that, and set my trpc client to use that /ws
prefix when creating the websocket client, the issue got resolved! No more hanging, all requests are now going through perfectly fine.
@alex / KATT any ideas on why this is necessary?
Feels like something is potentially broken somewhere deep in the trpc <-> fastify adapter.Might be best to write up a GitHub issue for this if you think itβs a defect. Iβve not used these APIs in tRPC so canβt help personally though
Yeah good call, will definitely do that π