Error "write EPIPE" causes client to disconnect but server keeps running
See original GitHub issueI get an error message on the server saying “Found error: Error: write EPIPE” when I use the following code to send messages from server to client and use an error listener. The error message is from the error listener I write on server. (Some codes are on the client which I didn’t post here)
try {
ws.send(msg, function(error) {
if(error == undefined)
return;
else
logger.debug("Async error:"+error);
});
} catch(e) {
logger.debug("Sync error: " + e);
ws.close();
}
wss.on('error', function error(err) {
console.log('Error: ' + err.code);
});
Error listener is inside wss.on('connection', function(ws, req) {})
:
ws.on('error', function(err) {
logger.debug('Found error: ' + err);
});
ws.on('close', function() {
logger.debug('connection closed.');
});
When I get this error, the client closes (readyState is not open), but the server keeps running. Is there anything I can do to figure out what causes the error and closes the client? I am running a realtime game. I didn’t do anything special other than just run the client normally and the client computer is in my room. I wonder if this is related to the server thinking the client is in idle status. For example, when I send little data from client to the server, the client crashes, when I keep pressing the mouse button, it sends messages to the server very often and the client is always alive.
I have used the “ping-pong” code on the server. But not sure if I need to implement that on the client.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
crazyyi It should be outside of onconnection. If you set it to inside of onconnection then it will be repeated for every socket connection.
That is hard to reproduce using only ws. I need to figure out some other way. But when I am testing it today. I found that after a while all sockets are terminated. I use the following code:
After a few seconds all of the 30 something connected bots/clients are terminated (with log message “terminating socket”). I try to understand the ping-pong example but I think maybe I miss something?
UPD: After I took this part out of the
wss.on('connection')
and put it outside of this listener, the terminate thing doesn’t happen any more.