clients
clients copied to clipboard
Manipulating TCP keep-alive settings
I ran into an issue recently where a client was stuck waiting on a host that had crashed and rebooted, but never ended the connection because there wasn't any TCP traffic. This situation could have been detected and remedied earlier by configuring the TCP connection to send keep-alive probes. I took a look, and Restify currently has an option _keep_alive
which will enable keep-alive on the socket. It would be nice if there was a way to also set the initial delay (TCP_KEEPIDLE
) in sending the probe (the second argument to .setKeepAlive()
).
I don't know exactly what the interface should look like, but it could be something along the lines of:
{
"keep_alive": {
"initial_delay": <milliseconds>
}
}
(Or perhaps just replace _keep_alive
. Since _keep_alive
doesn't seem to be currently documented, and it starts with an underbar, I'm guessing it's not considered a stable option?)
If node ever grows a way to also set TCP_KEEPCNT
and TCP_KEEPINTVL
, then additional fields could be added to the object for manipulating those parameters on the socket.
+1 for this, I have a situation where I effectively want to disable tcp keep alive
@melloc
server.server.on('connection', (socket) => {
socket.setTimeout(timeout);
});