-
-
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
Detecting broken connections fails with RSV1 must be clear
on node v20.11.0
#2193
Comments
Same happens with module version v8.10 on node 20.11.0 When multiple connections are made to the server, they do not drop all at the same time, but more after they are done. E.g:
|
The error you are seeing happens when a client sends an invalid frame. See #2169. Also this snippet app.get('/', (req, res) => {
if (!req.headers['upgrade'] || !req.headers['connection']) {
// no websocket handshake
res.status(421).end();
} else {
wss.handleUpgrade(req, req.socket, req.headers, (ws) => {
ws.isAlive = true;
ws.on('pong', () => {
ws.isAlive = true;
});
wss.emit('connection', ws, req);
});
}
}); is wrong. |
On second look, it seems that the |
Thanks for the response. But what i do not understand, why this just happens after a update from node 16 to 20. In v16 everything works fine and like expected. Why is this not the case after a update to v20?
This happens the other way around. Seems like the server sends a invalid frame. // PROBLEM START HERE
let interval = setInterval(() => {
wss.clients.forEach((ws) => {
if (!ws.isAlive) {
ws.terminate();
return;
}
ws.isAlive = false;
ws.ping();
});
}, 5000);
wss.on("close", () => {
clearInterval(interval);
});
// PROBLEM ENDS HERE For the upgrade handling part, i never had any issues doing it this way. I used the approach with express because i have multiple websocket endpoints and like the url/http request handling that express provides. Regardless how the upgrade is done, why does it (not) work when the broken connection detection part is (un-)commented? The error only happens when ping events are send and node =<16. At nearly exact after ~80 seconds. Makes no sense to me. |
What do you mean? The websocket handshake is done, and You can run it on your own. Its a minimal reproducible example. |
You are right with the part how i handle the websocket upgrade. What i find interesting is, that, when i add to my existing code (found here: expressjs/express#2594 (comment)): server.on("upgrade", (req, socket, head) => {
let res = new http.ServerResponse(req);
res.assignSocket(socket)
res.on("finish", () => {
res.socket.destroy();
});
app(req, res);
}); Without changing anything else, the problem is resolved and it works. wss.handleUpgrade(req, req.socket, req.headers, (ws) => {
ws.isAlive = true;
ws.on("pong", () => {
ws.isAlive = true;
});
wss.emit("connection", ws, req);
}); What/Why is |
Because the socket is freed when the |
Do you see any downsites how i handle the upgrade/routing stuff this way? |
Keep all the WebSocket stuff in the |
The error you are seeing is probably caused by some spurious HTTP stuff written to the raw socket used by the WebSocket. |
Makes somehow sense, but why "exactly" after ~1:20 and only when the ping events from How to detect and close broken connections? are used? |
Maybe your issue started after this change nodejs/node#43522. |
I don't know, probably because there are other open sockets. |
Thank you for helping. I close this issue. its resolved for me and not a problem of the ws package :) |
Is there an existing issue for this?
Description
When the "How to detect and close broken connections?" code from the FAQ is used, the client disconnects after ~1:20 (1 Minute, 20 seconds).
Minimal reproducible example:
index.js
package.json
When the following code is commented, nothing happens and it works like expected:
I only noticed because i installed a new OS and node.js version. On node v16.20.2 nothing happens, and the broken connection detection works.
ws version
8.10
Node.js Version
20.11.0
System
System:
OS: Linux 5.4 Ubuntu 18.04.6 LTS (Bionic Beaver)
CPU: (8) x64 Intel(R) Core(TM) i5-8365U CPU @ 1.60GHz
Memory: 7.18 GB / 15.45 GB
Container: Yes
Shell: 4.4.20 - /bin/bash
Expected result
The client should work and do not exit with the error.
Since node 20.11.0 does not work on my OS, i used docker to test it.
But it also happens on Ubuntu Unity 23.10 with node 20.11.0.
Test with the client that this package provides and
wscat --connect=127.0.0.1:8123
(v5.1.0)Actual result
No response
Attachments
test-ws-timeout.zip
The text was updated successfully, but these errors were encountered: