-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
RangeError: Invalid WebSocket frame: RSV2 and RSV3 must be clear #2098
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
Comments
It means the |
You can reproduce like this: const WebSocket = require('ws');
const server = new WebSocket.WebSocketServer({ port: 0 }, function () {
const websocket = new WebSocket(`ws://localhost:${server.address().port}`);
websocket.on('open', function () {
const chunk = Buffer.from('a180', 'hex');
websocket._socket.write(chunk);
});
});
server.on('connection', function (websocket) {
websocket.on('error', console.error);
}); |
See also #154. |
thanks I added a comment to that thread - looking for info on the 'upgrade' event and handleUpgrade, never heard of those, I will look at the docs |
@lpinca I'm encountering this invalid frame error fairly-consistently with iOS Safari. Unfortunately, when it happens it disconnects all active websocket connections and they're unable to reconnect. I've reviewed the following:
Based on feedback in those issues, I've added the following to my server: ws._socket.prependListener('data', (data) => console.log('ws data', data.toString()));
ws.on('error', (error) => {
console.error(error);
}); All normal/working frames are shown as binary data, but the frame that breaks the websocket connection is clear text:
In my test, I have Windows Chrome connected and working perfectly for days. When I make a connection with an iOS Safari device, I often see the above problematic frame. Once the frame is seen, the Chrome connection is dropped and cannot reconnect until the server is restarted. I realize this is likely an issue with the iOS WebSocket implementation, but it shouldn't be crashing the |
@sysrage make sure that the |
@lpinca the listener is never removed. I can keep refreshing the page in iOS and keep getting invalid frame errors (and crashing other clients). |
@sysrage see #2098 (comment). The server does not crash. |
Sorry, terrible wording all-around on my part. You're correct that nothing is crashing. However, in my configuration, other clients are getting disconnected. The server stays up and reloading the page does re-connect them. So, my auto-reconnect code is apparently busted since reloading the page works. But, I don't believe a bad frame from one client should disconnect other clients. I'll expand your minimum repro and test with multiple clients to verify. Thank you for the input. |
It shouldn't be possible because the TCP connection is not shared. There is one socket for each |
You're right. It was a bug in my code removing other connections. Sorry for wasting your time! |
Uh oh!
There was an error while loading. Please reload this page.
Is there an existing issue for this?
Description
Not sure what causes this error, but looking for find away around it.
In a child process, I have:
in the parent, I create the child using:
here is the full stack trace;
ws version
"version": "8.11.0",
Node.js Version
v18.12.1
System
System:
OS: macOS 12.6
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 24.73 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Expected result
No response
Actual result
No response
Attachments
No response
The text was updated successfully, but these errors were encountered: