Invalid WebSocket frame: RSV2 and RSV3 must be clear
See original GitHub issueGood afternoon, I’m writing to report an important websocket issue. I would have loved to send a PR, but the reality of the facts is that so far I’ve not been able to even reproduce the issue. I’m sure this is going to be useful for someone else and we can find some workaround together.
Impact
The server crash with:
code: "WS_ERR_UNEXPECTED_RSV_2_3"
message: "Invalid WebSocket frame: RSV2 and RSV3 must be clear"
stack: "RangeError: Invalid WebSocket frame: RSV2 and RSV3 must be clear
at Receiver.getInfo (/app/node_modules/ws/lib/receiver.js:176:14)
at Receiver.startLoop (/app/node_modules/ws/lib/receiver.js:136:22)
at Receiver._write (/app/node_modules/ws/lib/receiver.js:83:10)
at writeOrBuffer (node:internal/streams/writable:392:12)
at _write (node:internal/streams/writable:333:10)
at Writable.write (node:internal/streams/writable:337:10)
at Socket.socketOnData (/app/node_modules/ws/lib/websocket.js:1272:35)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)"
type: "RangeError"
I believe this started happening since an upgrade to node 18.
Preliminary Analysis
Digging over the internet, I found some recent resources that well describe what happens.
Recent conversation on websocket/ws issue 1354 .
Recent workaround on trpc 2522.
Summary: it looks like some safari browsers are buggy and set some bits without negotiating them with the server.
If the workaround on trpc actually works, I’m not sure why this would not be enough: https://github.com/mercurius-js/mercurius/blob/master/lib/subscription-client.js#L86
Issue Analytics
- State:
- Created a year ago
- Comments:9
Top Related StackOverflow Question
The
@fastify/websocketchange shipped!@mcollina thank you for merging the PR. As soon as you release a new version I’ll be happy to create a PR here. I would love to get my fix out before the weekend 😃