Invalid WebSocket frame: RSV2 and RSV3 must be clear

See original GitHub issue

Good 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:closed
  • Created a year ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
mcollinacommented, Nov 3, 2022

The @fastify/websocket change shipped!

1reaction
marcolanarocommented, Nov 3, 2022

@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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid WebSocket frame: RSV2 and RSV3 must be clear #1354
I'm using ws as a client in my node application, and when I attempt to connect to the host, the connection is closed...
Read more >
Error `RSV2 and RSV3 must be clear` in `ws` - Stack Overflow
According to RFC6455: RSV1, RSV2, RSV3: 1 bit each. MUST be 0 unless an extension is negotiated that defines meanings for non-zero values....
Read more >
RSV2 and RSV3 must be clear" error and websocket ...
When I try to place an order using the JavaScript client, I get the above error mentioned in the title. Then the websocket...
Read more >
[Solved] Any one get SSL proxy working? - MAAS | Discourse
... Use wscat -c return error: Invalid WebSocket frame: RSV2 and RSV3 must be clear But… ... Same proxy setup for other websocket...
Read more >
Uncaught Exception in engine.io - Vulners
RangeError: Invalid WebSocket frame: RSV2 and RSV3 must be clear at Receiver.getInfo (/.../node_modules/ws/lib/receiver.js:176:14) at ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found