Server crashes with Invalid WebSocket frame: RSV1 must be clear

See original GitHub issue
  • I’ve searched for any related issues and avoided creating a duplicate issue.

Description

The example code no longer works. The server will throw RangeError: Invalid WebSocket frame: RSV1 must be clear and exit.

Reproducible in:

  • version: 7.3.1
  • Node.js version(s): v12.18.2
  • OS version(s): Mac OS 10.15.5 (19F101)

Steps to reproduce:

npm install ws
node -e """
const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 8080 });

wss.on('connection', function connection(ws) {
  ws.on('message', function incoming(message) {
    console.log('received: %s', message);
  });

  ws.send('something');
});
"""
npx wscat -c ws://localhost:8080/ -x "Hello"

Expected result:

It should log the message

Actual result:

events.js:292
      throw er; // Unhandled 'error' event
      ^

RangeError: Invalid WebSocket frame: RSV1 must be clear
    at Receiver.getInfo (/Users/anthony/src/tmp/node_modules/ws/lib/receiver.js:178:14)
    at Receiver.startLoop (/Users/anthony/src/tmp/node_modules/ws/lib/receiver.js:131:22)
    at Receiver._write (/Users/anthony/src/tmp/node_modules/ws/lib/receiver.js:78:10)
    at doWrite (_stream_writable.js:403:12)
    at writeOrBuffer (_stream_writable.js:387:5)
    at Receiver.Writable.write (_stream_writable.js:318:11)
    at Socket.socketOnData (/Users/anthony/src/tmp/node_modules/ws/lib/websocket.js:872:35)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
Emitted 'error' event on WebSocket instance at:
    at Receiver.receiverOnError (/Users/anthony/src/tmp/node_modules/ws/lib/websocket.js:777:13)
    at Receiver.emit (events.js:315:20)
    at errorOrDestroy (internal/streams/destroy.js:108:12)
    at onwriteError (_stream_writable.js:418:5)
    at onwrite (_stream_writable.js:445:5)
    at Receiver.startLoop (/Users/anthony/src/tmp/node_modules/ws/lib/receiver.js:152:5)
    at Receiver._write (/Users/anthony/src/tmp/node_modules/ws/lib/receiver.js:78:10)
    [... lines matching original stack trace ...]
    at Receiver.Writable.write (_stream_writable.js:318:11) {
  [Symbol(status-code)]: 1002
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lpincacommented, Jul 20, 2020

I restarted my Mac, and now it works.

Ok, I’m closing then.

1reaction
aantthonycommented, Jul 20, 2020

I tried adding the error handler, it logged the same error. I then tried making a complete example (https://github.com/aantthony/ws-example). Doing a git pull, npm install && node index.js, then npm test resulted in the error.

I restarted my Mac, and now it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RangeError: Invalid WebSocket frame: RSV1 must be clear
someone keeps trying to crash my WebSocket server, and this error keeps getting sent when they try. Is there any possible fix to...
Read more >
Server crashes with Invalid WebSocket frame: RSV1 must be ...
Server crashes with Invalid WebSocket frame : RSV1 must be clear.
Read more >
Invalid WebSocket frame: RSV1 must be clear - Monocle Forums
I am getting the 'Invalid WebSocket frame: RSV1 must be clear' error. I have already tried uninstalling and reinstalling.
Read more >
Invalid WebSocket frame: invalid payload length 126
I see, is this error crashing the server, or it just prints this error and server continues running? I've never seen this, but...
Read more >
iOS 15 WKWebView websocket behaviour - Apple Developer
A test web socket to another server seems to be working. ... this socket is very important for the functionality of our app...
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