Node.js net server not receiving some client disconnects

I have a Node.js net socket server running which works fine with a low number of clients connected to it. When I up the number to 200 client connections though, all of the initial connections establish and communicate correctly but when I hit Ctrl-C to close the client program only some of the disconnects are received on the server (via the Error: read ECONNRESET message).

I am listening to the events: close, timeout, disconnect, error and end I also check if the data event receives a length 0 data, but this situation is never triggered.

The error/disconnect events just appear to not trigger sometimes when there are a lot of disconnects at the same time.

The server and client receives no exceptions or errors while running; both are Node.js.

netstat -i shows that all connections are terminated on the client

lsof -i shows many connections still established on the server

(example of connection left open on the server from lsof)

node 5569 root 18u IPv4 4236971 0t0 TCP xxx.xxx.xxx.xxx:2048->xxxxxx.hsd1.ca.comcast.net:12501 (ESTABLISHED)

Has anyone else run across this?

You should consider incorporating some sort of special ping/keepalive message that both the client and server send periodically to more accurately/quickly check for dead sockets on both ends.

It appears that ECONNRESET is only triggered when the connection closes while there is data being written/read on the socket. If the socket closes when there is no traffic on it AND the client does not send a FIN packet to the server (as in the client has crashed or abruptly closed the connection) AND there is no timeout/keepalive on the socket, then the other side never knows that the connection has been terminated until it tries to send something on the socket again and realizes that the connection is broken.