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

"Invalid WebSocket frame: RSV1 must be clear" Error on WS 8.8 #2058

Closed
1 task done
rcaner opened this issue Jun 13, 2022 · 12 comments
Closed
1 task done

"Invalid WebSocket frame: RSV1 must be clear" Error on WS 8.8 #2058

rcaner opened this issue Jun 13, 2022 · 12 comments

Comments

@rcaner
Copy link

rcaner commented Jun 13, 2022

Is there an existing issue for this?

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

Description

Before the previous version WS, we have no issue. But after upgrading ws 8.8 we encounter this error.

"Invalid WebSocket frame: RSV1 must be clear".

While Client side is requesting connection, API's are down and restarted.

Do you have any suggestion about this topic?

PS: I check your changes, you change only environment variables on bufferutil and utf8, how we can use these environment variables?

ws version

8.8.0

Node.js Version

16.15.1

System

OS: Linux 5.4 Debian GNU/Linux 10 (buster) 10 (buster)
CPU: (40) x64 Intel(R) Xeon(R) CPU E5-2658 v2 @ 2.40GHz
Memory: 19.59 GB
Container: Yes
Shell: 5.0.3 - /bin/bash

Expected result

Connection should be successful and not crashed APIs.

Actual result

"Invalid WebSocket frame: RSV1 must be clear".

Attachments

No response

@lpinca
Copy link
Member

lpinca commented Jun 13, 2022

Duplicate of #2055 and #2019.

@lpinca
Copy link
Member

lpinca commented Jun 13, 2022

PS: I check your changes, you change only environment variables on bufferutil and utf8, how we can use these environment variables?

Set them at the process level. For example

$ WS_NO_BUFFER_UTIL=1 WS_NO_UTF_8_VALIDATE=1 node app.js

@rcaner
Copy link
Author

rcaner commented Jun 13, 2022

We tried again with #2019 but problem not solved. our API's always failed after upgrading 8.8.0. But I can ask another question, we can't use websocket library in browser. So we have to use JS Websocket , is there any problem about that also ?

@rcaner rcaner closed this as completed Jun 13, 2022
@rcaner rcaner reopened this Jun 13, 2022
@rcaner
Copy link
Author

rcaner commented Jun 13, 2022

Accidentally close so sorry about that.

@lpinca
Copy link
Member

lpinca commented Jun 13, 2022

So we have to use JS Websocket , is there any problem about that also ?

No, that is ok.

About your problem, write and share a minimal reproducible test case using only ws.

@lpinca
Copy link
Member

lpinca commented Jun 13, 2022

You can send the invalid frame like this:

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('c200', 'hex'));
  });
});

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

@rcaner
Copy link
Author

rcaner commented Jun 13, 2022

Actually we don't send a message at the startup, We only connect socket and API's are crashed with this error. I will prepare a nodejs code for reproducing. Thank you for your support

@lpinca
Copy link
Member

lpinca commented Jun 13, 2022

It doesn't matter when the invalid frame is sent. It can happen at any time. Make sure that the listener of the 'error' event is not removed before the 'close' event is emitted.

@rcaner
Copy link
Author

rcaner commented Jun 13, 2022

We found smt but we didn't understand how to reproduce it. In Windows machine code works, but in the docker containerized linux nodejs(node 16) machine not working. Always return 1002 code number while connecting WSS.

@lpinca
Copy link
Member

lpinca commented Jun 13, 2022

I think there is something wrong in your setup but anyway, the server should not crash if there is a listener for the 'error' event on the WebSocket instance when the error is raised. Without a test case to investigate there is not much we can do.

@rcaner
Copy link
Author

rcaner commented Jun 14, 2022

Ok. Thank you very much Ipinca we will investigate into this issue. I'll inform you our solution.

@rcaner
Copy link
Author

rcaner commented Jun 15, 2022

Hey Ipinca, I finally found the problem. Like as you said your code works as expected, but our security guys try smt in the firewall ip intervention rules added. All WS connection requests are distorted. There is no problem right now. Thank you for your support

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

2 participants