-
-
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
read ECONNRESET error on disconnect (ws 3.3.3) #1256
Comments
Issue is caused by lack of error listener on the socket, and can be fixed like so:
This isn't documented in the README.md, and seems to be a pretty big breaking change. |
You need to always add a listener for the |
his is the case for the latest Google browsers |
@lpinca So can we add it to README? If it's a required thing to do, why is it absent there? Edit. This is totally a good change, but it should be at least documented properly. |
@lpinca You document that that event is where any errors from underlying To me, because you have a I think is a reasonable assumption to make, given that clients disconnecting is a perfectly normal event for a socket server. |
We've been running into this issue as well, but it's puzzling. Chrome 62 and below do not cause an error using these steps, and neither do any other browsers that I've tested (Firefox 57, Firefox Mobile (57), Chrome Mobile (62)). Further, with Wireshark I wasn't able to observe any significant difference in the close frames. Both Firefox and Chrome send the same 1001 closing code ("Going away"). With the error handler, it appears when closing a Chrome 63 tab that the error handler and the close handler are called at roughly the same time, but I haven't yet confirmed this. |
Yes because it shouldn't, the issue seems to happen only on Chrome 63.
Swallowing errors is never a good idea. Developers can ignore errors but they may want to know if the connection was closed cleanly or not. I didn't check but maybe latest Chrome sends the close frame and abruptly closes the connection immediately after that. |
@lpinca That all makes far more sense; that's a mistake on my part - I didn't test it with another browser, and so assumed that that was something that commonly happens with client disconnections. |
|
Nevermind, here is a test case which doesn't use const assert = require('assert');
const crypto = require('crypto');
const http = require('http');
const GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
const data = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script>
(function () {
var ws = new WebSocket('ws://localhost:8080');
ws.onopen = function () {
console.log('open');
};
})();
</script>
</body>
</html>`;
const server = http.createServer();
server.on('request', (req, res) => {
res.setHeader('Content-Type', 'text/html');
res.end(data);
});
server.on('upgrade', (req, socket) => {
const key = crypto.createHash('sha1')
.update(req.headers['sec-websocket-key'] + GUID)
.digest('base64');
socket.on('error', console.error);
socket.on('data', (data) => {
assert.ok(data.slice(0, 2).equals(Buffer.from([0x88, 0x82])));
socket.write(Buffer.from([0x88, 0x00]));
});
socket.write([
'HTTP/1.1 101 Switching Protocols',
'Upgrade: websocket',
'Connection: Upgrade',
`Sec-WebSocket-Accept: ${key}`,
'\r\n'
].join('\r\n'));
});
server.listen(8080, () => console.log('Listening on *:8080')); |
ws@3.3.3 stopped swalling ECONNRESET inside the library upon a connection close event. This commit swallows it when we know we are attempting to disconnect. Related to websockets/ws#1256.
I'm in the same boat.
this doesn't solve the problem. |
@ProgrammingLife it should. |
I can confirm this statement, when the handler is applied to the server. No more crashes when applied to each connection individually. These errors occur quite often on Chrome V 63.0.3239.84 (=latest for my distribution). FF 57.0.3 doesn't produce this error at all. Same with Edge on Windows clients. Node v8.9.3 ws 3.3.3 ubuntu1~16.04.5 Linux 4.4.0-21-generic (x86_64) |
According to https://bugs.chromium.org/p/chromium/issues/detail?id=798194#c6 this works as intended. What we can do here is adding a default Thoughts? |
- Listens for error events on the websocket instance to avoid uncaught ECONNRESET exceptions. When no listener is attached to error event from the websocket - the ECONNRESET expception is thrown: websockets/ws#1256 This is also somewhat relevant: livereload/livereload-server#2
Summary: There is a scary comment in `BigDigServer` about not handling WS/HTTPS server errors, and I think I managed to encounter one. I'm not sure how to reproduce it, but we can at least see if this is happening in the wild. I thought this might've been related to websockets/ws#1256 but we're still using ws 3.2.0 so that wasn't exactly it. But I could imagine the HTTPS server erroring in other cases maybe? I assigned a logger category so that these are easier to find. Reviewed By: wanderley Differential Revision: D8954324 fbshipit-source-id: 9582ebb9a394eafbb52aba1584998ef6c4523ca2
@kahluagenie here because of Devskiller interview assessment? I wonder how many people are coming here because of bad spec tests in timed Devskiller assessments? Here is my theory: I think the
or,
You have three hours to scour and find the GitHub issue before you get the senior level remote-coffee-shop Node.JS guru position. If you found this issue. Congrats. You won. The funny thing I read this and I wonder if everyone is making this honest mistake, or if we're all here for the same malformed https://devskiller.com/coding-tests/middle-javascript-developer-node-js-server-side-step-tracker/ |
Haha, negative. I was using ws for a project of mine, so was figuring stuff out when I ran across the issue. All good now though! |
WebSockets can throw an error event that has to be captured in node to prevent application crashing. This seems to be crashing WebKit Linux on some of the bots with the `ECONNRESET` error: - https://github.com/microsoft/playwright/runs/544357239 WS-related `ECONNRESET` error discussion: - websockets/ws#1256
Apologies for commenting on an old issue, but this is still a problem.
Whenever a client disconnects while a large amount of data is being sent, I consistently get full server crashes. Using ws 7.4.2, running on Node v14.15.4 on Ubuntu 20.04. I'm actually unsure if this is a node internal error or has something to do with this library, since I also get ECONNRESET errors that I can't seem to catch from time to time. edit:Right as I finished up writing this post, I figured the listener was attached too late to the For anyone running into similar issues: The fix for me was to attach a listener to the So, instead of: httpServer.on('upgrade', (request: IncomingMessage, socket: Socket, head: Buffer) => {
socket.on('error', () => console.log('poof!'));
}); All you have to do is bind the listener during the httpServer.on('connection', (socket: Socket) => {
socket.on('error', () => console.log('poof!'));
}); |
@haroldiedema Could you please provide us with a full proof of concept that makes your server crash? |
@cluxter Sorry, I don't think I can. It was triggered by a combination of circumstances (high CPU load, multiple active connections, etc.) The problem was on my end. All I had to do was immediately attach a listener to the The problem specifically is when the client connects (page is loading), and before the HTTP server Anyway, like I said, it's not a problem with the 'ws' library. People running into this issue should simply attach the |
@haroldiedema that listener is already added by Node.js as per https://github.com/nodejs/node/blob/v15.6.0/lib/_http_server.js#L498. |
Description
Upon updating to ws 3.3.3, when a client disconnects the following exception is thrown:
Code works fine in previous version.
Reproducible in:
version: 3.3.3
Node.js version(s): v8.9.1
OS version(s): Windows 10 Pro, Fall update
Steps to reproduce:
Expected result:
The disconnect is handled gracefully, with the 'close' event being called.
Actual result:
An exception is thrown, which crashes the app:
The text was updated successfully, but these errors were encountered: