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

Error: RSV1 must be clear #1140

Closed
wyzxxx123 opened this issue Jun 13, 2017 · 22 comments
Closed

Error: RSV1 must be clear #1140

wyzxxx123 opened this issue Jun 13, 2017 · 22 comments

Comments

@wyzxxx123
Copy link

wyzxxx123 commented Jun 13, 2017

  • [1 ] I've searched for any related issues and avoided creating a duplicate issue.

Description

Occasional players connecting 10 seconds

Reproducible in:

version:3.0.0
Node.js version(s):v6.10.0
OS version(s):windows server 2008 r2 enterprise

Steps to reproduce:

no way

Expected result:

NO ERROR

Actual result:

Error: RSV1 must be clear
at Receiver.getInfo (D:\HallServer\node_modules\ws\lib\Receiver.js:191:18)
at Receiver.startLoop (D:\HallServer\node_modules\ws\lib\Receiver.js:153:16)
at Receiver.add (D:\HallServer\node_modules\ws\lib\Receiver.js:139:10)
at Socket._ultron.on (D:\HallServer\node_modules\ws\lib\WebSocket.js:142:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:548:20)

Attachments:

@lpinca
Copy link
Member

lpinca commented Jun 13, 2017

This error means that the client is sending a compressed frame but the permessage-deflate extension is disabled.

There isn't anything actionable to do apart from handling the error.

@wyzxxx123
Copy link
Author

thx

@TinyDobbins
Copy link

hey @lpinca got same error when using ws. interesting that when I use uws this error doesn't happens on server side. looks like there is way to avoid this error.. any idea?

@lpinca
Copy link
Member

lpinca commented Apr 13, 2018

uws has no errors, it simply closes the connection when an error occurs without any notice. Add a listener for the 'error' event to prevent the process from crashing and eventually ignore errors. Also see #1354 (comment) which might be related.

@ppeccin
Copy link

ppeccin commented Apr 27, 2018

Hello. I'm getting the same error if the client connecting is from MacOS/Chrome, but NOT from Windows/Chrome. What can I do on the Server or Client to be able to connect from MacOS?
I can't make it work on the Mac. Same code everywhere.... :-(

@ashbrener
Copy link

I am experiencing the same issue on node v8.11.3 and v10.6.0

node_modules/ws/lib/receiver.js:167
      return error(RangeError, 'RSV1 must be clear', true, 1002);
             ^
RangeError: Invalid WebSocket frame: RSV1 must be clear
    at Receiver.getInfo (/node_modules/ws/lib/receiver.js:167:14)
    at Receiver.startLoop (/node_modules/ws/lib/receiver.js:121:22)
    at Receiver._write (/node_modules/ws/lib/receiver.js:69:10)
    at doWrite (_stream_writable.js:397:12)
    at writeOrBuffer (_stream_writable.js:383:5)
    at Receiver.Writable.write (_stream_writable.js:290:11)
    at TLSSocket.socketOnData (/node_modules/ws/lib/websocket.js:795:35)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at TLSSocket.Readable.push (_stream_readable.js:208:10)
    at TLSWrap.onread (net.js:597:20)

Have wrapped ws.send() in a try / catch as well as set perMessageDeflate=false in the client constructor options.

@Esqarrouth
Copy link
Contributor

Esqarrouth commented Dec 11, 2018

This error means that the client is sending a compressed frame but the permessage-deflate extension is disabled.

There isn't anything actionable to do apart from handling the error.

And how would we handle this particular error?

I've read this #1191 (comment).

But I already got the following code running in my server and it doesn't seem to be catching this error:

        webSocket.on('error', function(error) {
            console.log(webSocket.id + ':' + error)
        })

@shellscape
Copy link

@goktugyil wow we were both working on this problem at the same time today. See my comment here: nodejs/node#17806 (comment). It appears that Node v10.14.0 introduced some kind of regression.

@Esqarrouth
Copy link
Contributor

I'm using v10.11.0 in dev environment and v10.10.0 in the server that crashed. Server crashed like 60 times in 2 minutes. And then nothing happened for a day. What do you suggest I do about this?

@shellscape
Copy link

@goktugyil no clue. on our end, we were able to isolate it to v10.14.x

@Esqarrouth
Copy link
Contributor

Esqarrouth commented Dec 11, 2018

@shellscape
I see. :(
Is there a specific place of origin for this bug? I'm not using permessage-deflate.

@lpinca
Copy link
Member

lpinca commented Dec 11, 2018

@goktugyil here is a quick way to reproduce:

const { request } = require('http');
const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 0 }, () => {
  const req = request({
    port: wss.address().port,
    headers: {
      Connection: 'Upgrade',
      Upgrade: 'websocket',
      'Sec-WebSocket-Key': 'dGhlIHNhbXBsZSBub25jZQ==',
      'Sec-WebSocket-Version': 13
    }
  });

  req.end(Buffer.from([0xC1, 0x05, 0x5f, 0xeb, 0xe5, 0xf0, 0x1c]));
});

wss.on('connection', (ws) => {
  ws.on('error', console.error);
});

@Esqarrouth
Copy link
Contributor

port: wss.address().port,

How does this work without init() first?

@shellscape
Copy link

@lpinca would that be a simpler reproduction that should be posted on nodejs/node#24958?

@lpinca
Copy link
Member

lpinca commented Dec 11, 2018

@shellscape no because what I posted above is done on purpose, the same error was caused by a bug in Node.js core but that is different. The first byte was dropped so the frame was still malformed but not on purpose. Hope it makes sense.

@Esqarrouth
Copy link
Contributor

@goktugyil here is a quick way to reproduce:

const { request } = require('http');
const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 0 }, () => {
  const req = request({
    port: wss.address().port,
    headers: {
      Connection: 'Upgrade',
      Upgrade: 'websocket',
      'Sec-WebSocket-Key': 'dGhlIHNhbXBsZSBub25jZQ==',
      'Sec-WebSocket-Version': 13
    }
  });

  req.end(Buffer.from([0xC1, 0x05, 0x5f, 0xeb, 0xe5, 0xf0, 0x1c]));
});

wss.on('connection', (ws) => {
  ws.on('error', console.error);
});

I couldn't get this to compile at all.

@adipascu
Copy link

adipascu commented Feb 2, 2019

I am still having this issue in production, can @wyzxxx123 or somebody else reopen it?

@rvdende
Copy link

rvdende commented Sep 15, 2019

I found I get this serverside when using an espruino esp32 and trying to send a json object directly. The fix is to first turn it into a string ws.send(JSON.stringify({data:"asdf}));

@n-elloco
Copy link

n-elloco commented Sep 9, 2020

Hello, @lpinca. We use your library. Generally, everything is OK, but sometimes there are some clients when we got the error RSV1 must be clear. I read different threads here, but I don't understand, how I can reproduce it on the client side. What should I send to server for getting this error?

@lpinca
Copy link
Member

lpinca commented Sep 9, 2020

@n-elloco assuming that permessage-deflate is disabled on the server (it is by default) you can send the following bytes.

0xc1 0x80
const WebSocket = require('ws');

const server = new WebSocket.Server({ port: 0 }, function () {
  const ws = new WebSocket(`ws://localhost:${server.address().port}`);

  ws.on('open', function () {
    ws._socket.write(Buffer.from([0xc1, 0x80]));
  });
});

server.on('connection', function (ws) {
  ws.on('error', console.error);
});

@Esqarrouth
Copy link
Contributor

Esqarrouth commented Mar 17, 2022

The code above produces the following error:
Screen Shot 2022-03-17 at 12 35 44
I've ran it 20 times, couldn't get it to crash anything.

I've also ran this one, errors, but no crashes.
#1140 (comment)


https://sentry.io/share/issue/5193b3cca33545d8971852049a5e2457/

Screen Shot 2022-03-17 at 12 41 15

However when this issue happens to me, 83% of the time it is handled. 17% of the time it is a full server crash. Does the exception stack make any sense to anyone?

The socket that connected is using Chrome 99.0.4844.51 Windows 10.0. For my side looks like a normal user


It seems when this event happens, it happens multiple times around the same times, makes sense.

Screen Shot 2022-03-17 at 13 02 47


I get billions of socket connections and events on my site, no problem.
But randomly I get a full server crash from RSV1 once every few months, I still have no idea what causes it.


Currently using
Node: v12.22.10
ws: 6.2.2

@tegila
Copy link

tegila commented Feb 22, 2023

i don't even have a line of my code where i can put a try {} catch statement :(

ip[x-forwarded-for]: 186.210.46.219
node:events:491
      throw er; // Unhandled 'error' event
      ^
RangeError: Invalid WebSocket frame: RSV1 must be clear
    at Receiver.getInfo (/data/nostr/server/node_modules/ws/lib/receiver.js:199:14)
    at Receiver.startLoop (/data/nostr/server/node_modules/ws/lib/receiver.js:146:22)
    at Receiver._write (/data/nostr/server/node_modules/ws/lib/receiver.js:84: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 (/data/nostr/server/node_modules/ws/lib/websocket.js:1274:35)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
Emitted 'error' event on WebSocket instance at:
    at Receiver.receiverOnError (/data/nostr/server/node_modules/ws/lib/websocket.js:1160:13)
    at Receiver.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'WS_ERR_UNEXPECTED_RSV_1',
  [Symbol(status-code)]: 1002
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests