-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Websocket RangeError: Invalid WebSocket frame: RSV2 and RSV3 must be clear #1354
Comments
It might be a bug that has been recently fixed in nodejs/node#17806 but I think not yet backported to Node.js 8. Try to use Node.js 9. If the issue persists please post the received data on the socket. You can do that by attaching a listener for the const ws = new WebSocket('ws://site:8765/ws');
ws.on('open', function () {
ws._socket.on('data', console.log);
}); |
@ztnark any update? |
Should be resolved in the next Node.js 8 version as well, presumably 8.11.2 :) |
Sorry, haven't had a chance to take a look yet. I'll give it a shot
tomorrow.
…On Wed, Apr 11, 2018, 4:38 PM Jeroen Vollenbrock ***@***.***> wrote:
Should be resolved in the next Node.js 8 version as well, presumably
8.11.2 :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1354 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AEsiXbmJMBwToHdBOQzqrVgK2vZHd24Sks5tnnfdgaJpZM4TKgtd>
.
|
@lpinca, good news. I can confirm that upgrading to Node.js 9 (11.1) fixes this issue. I can also test on 8.11.2, when released. Thank you. |
I'm closing then. Please reopen if the issue persists. |
Howdy all, As of today, electron is currently running node@8.9.3 in it's main process. So the solution of upgrading the local node version is not a viable option for electron app developers. Dan |
FWIW I'm hitting the same issue with Node 10 too, but I would expect that this is a server-side issue, with a server sending a frame with those flags that should actually not be set. |
I am experiencing a similar issue on node v8.11.3 and v10.6.0
Have wrapped ws.send() in a try / catch as well as set |
Are you getting it on the client or server? If it is on the server it's possible that a malicious client is sending faulty frames intentionally. If it's on client instead, you can try to log the received data ws.on('open', function () {
ws._socket.prependListener('data', function (chunk) {
console.log(chunk.toString('hex'));
});
}); |
@lpinca thank you for the fast response. This advice was most helpful, the error is on the client and I added the listener as you suggested. This led me to find what I think could be the cause. The server (which also uses ws) is aborting the handshake based on a certain condition (a custom override in our app) using a copy of the abortHandshake function. And so it is writing the following data to the socket: HTTP/1.1 401 Unauthorized
Connection: close
Content-type: text/html
Content-Length: 12
Unauthorized ... which the client receives and throws the RangeError on. Does this make sense? |
No not really, that should not trigger the |
Are you able to create a reproducible test case? If so please do it so I can investigate. |
Or are you writing that on the socket after the 101 response? In this case, yes, it makes sense. |
Its quite possible this is after the 101, my class inherits from WebSocket.Server and overrides the handleUpgrade function to inspect the client IP address and abort the handshake if unrecognized. |
You probably have your own reasons to do that (overriding |
FYI, this issue still reproduces on both WSL2 and Windows 10 for Node v14.15.4. I have a sample client that can crash a WS server instantly. I'm using pretty much the minimal sample - Server: https://github.com/tgraupmann/NodeJS_WS/blob/master/app.js This worked fine sending JSON payloads. I'm testing a C client with binary payloads which crash the server.
Also reproduced initially on WSL2.
The offending C client code looks like this:
This is the client library that I'm using - https://github.com/tgraupmann/libwsclient It's entirely that I'm using the websocket API incorrectly, and will take any recommendations for a better client that handles binary payloads in pure "C". That said, it's still able to crash the server though its incorrect use. I also have a direct repro for any that are interested in following up. |
wss.on('connection', function(ws) {
ws.on('error', console.error);
}); |
That's all it was. The server just needed an error handler to avoid crashing. And now it logs errors without exiting. Thanks! |
I'm seeing this in node v18.8.0 when connecting from a Safari client (latest Safari, latest iOS 16.3). Hard to reproduce: it does not happen on first connect, but after reloading the page. Yet after a couple of reloads it works, then breaks again. Sorry could not provide more details right now. Weird bug...don't even know if it comes from the ws library, just posting here because I found this issue while searching for answers More details It's probably been covered in this issue or elsewhere in ws already but I went looking around and it seems:
So, at least in my case, the Safari client seems to be incorrectly (?) setting these bits. It may the wrong fit for If that could be possible, then adding a const wss = new WebSocketServer({
server,
perMessageDeflate: false,
strictProtocol: false,
}); to permit these "non-conforming" messages could be a way to still serve clients that make these errors. |
@tgraupmann I have an error handler, but my websocket closes after showing this RangeError. |
@crisdosyago the spec specifically says that
I'm strongly against adding a Also, it is not the first time that Safari introduces bugs like this. See #1922. |
Understood @lpinca I know you don't want to dirty this library with irregularities or tolerances of those. Thank you for your consideration of this idea, it sounds like you've given this some serious thought and like you believe it's the right choice to not include here because doing so would mean your library would no longer meet the standard of quality you're trying to keep. I trust you. Thank you for your information--including on the other bug (how interesting! that Safari!)--and thanks for the amazing work on this great library! |
For more information, see websockets/ws#1354 Closes #290
I have set proper error handler on the websocket @lpinca can you help me with few hints.
|
Yes, make sure that the |
Yes removed error handler in tear down, and it caused it. Thanks! |
@misi Can you please provide a code example or reference for this use case? |
I was also struggling with such an issue for some time. Tried several different web socket clients, and always the same. Then I started breaking down my code, and it turned out that the following line was causing the issue in my case:
|
Hello author; Using node as a program to use ws, will inconsistent time between the user and server in the same time zone result in the issue of RSV2 and RSV3 must be clear? The node service on my end is installed using the Docker method |
Description
I'm using ws as a client in my node application, and when I attempt to connect to the host, the connection is closed with the error 'Websocket RangeError: Invalid WebSocket frame: RSV2 and RSV3 must be clear'.
It is worth noting that the connection is successful to a different host, but I believe this is a client issue?
It's also worth noting that faye-websocket functions correctly in the same situation.
Reproducible in:
version: 5.1.1
Node.js version(s): 8.9.4
OS version(s): Windows 7 Professional v6.1 (build 7601)
Steps to reproduce:
The text was updated successfully, but these errors were encountered: