Mikey A. Leonetti
Mikey A. Leonetti

Reputation: 3352

Node.js set setKeepAlive not stopping a timeout with setTimeout

I'm trying to figure out how Node.js's net class works with timeouts and keepalives. I am setting them on the server side and watching to see what difference it makes setting these variables. I notice that if I set the keepalive to the following:

// Set keepalive
socket.setKeepAlive( true, 30000 );

It will absolutely in fact send keepalive packets which I observe with Wireshark.

Keep alive with Wireshark

However, even if I subscribe to the socket's timeout event, the socket will not timeout. So I try setting the socket's timeout option.

// Set timeout variables
socket.setTimeout( 60000 );

Even combined with the keepAlive option, the socket still times out after 60 seconds pretty much after its last real transmitted packet.

Connection timeout

So my question is, what's the point of keepAlive if it doesn't really do anything to prevent socket timeouts?

Upvotes: 2

Views: 1201

Answers (1)

mscdex
mscdex

Reputation: 106736

socket.setTimeout() merely emits the timeout event when there has been no data received after whatever duration you specify. The socket.setKeepAlive() is for sending keepalive probes as a means for detecting dead sockets.

These two features are operating at two different "levels/layers." Keepalive probes are not considered "data," so that is why you're seeing the timeout event still.

Upvotes: 1

Related Questions