0

I'm using net.createServer(host, port) + flash socket client. When my game works for several hours and get on high load - the server starts to drop connections. The client get the "connected" event and immediately after that - the "close" event. It loops like this 3-4-5-6 times and connects. The server is not under heavy load. There is plenty of RAM and CPU resources.

My code looks like this:

var net = require("net"); 
server = net.createServer(function(socket) {
                socket.setTimeout(15000);
                socket.setKeepAlive(true);
                //used to store string socket data untill packet delimiter is received
                socket.myBuffer = ""; //(and then process the JSON message)

                socket.on("data", onData); 
                socket.on("error", onError);            
                socket.on("end", onClientDisconnect);
                socket.on("timeout", onClientDisconnect); 
});  
server.listen(port);

How can I debug the issue ? Is there any kind of code (mine) that could cause such thing ?

1 Answer 1

-1

It turned out to be because I did not checked for writable socket, before write something and becasuse I close the connection inside onError handler. So what is happening is: socket.write(..) triggers error because the socket is not writable (although is connected) and on error I close the socket, so the client starts reconnecting and this loops 3-7 times untill sending goes without exception.

2
  • You don't need to check for writability before writing, but you do need to check the result of writing.
    – user207421
    Jan 12, 2015 at 9:00
  • But this means I have to remove connection close code from onError handler, which will lead to hanging sockets in my connected clients array. Jan 12, 2015 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.