TCP keep-alive parameters not being honoured

tcptcp/ip

I have a server running on my Linux box, also on which the following commands were run:

$ cat /proc/sys/net/ipv4/tcp_keepalive_time
7200
$ cat /proc/sys/net/ipv4/tcp_keepalive_intvl
75
$ cat /proc/sys/net/ipv4/tcp_keepalive_probes
9

My server listens on port 58080, and I create a connection on it having set TCP keep-alive in my code. I then set Wireshark tracing this connection; a screenshot of the output is shown below:

Packets

You can see that the first keep-alive packet is sent after 7200 seconds, or 2 hours as expected (the value of 'tcp_keepalive_time'). However I would also expect each probe to be sent at 75 seconds (the value of 'tcp_keepalive_intvl'); what I see though is that each probe is sent at 2 hours.

Can someone please tell me why my configuration option for 'tcp_keepalive_intvl' is not being honoured?

UPDATE

It seems that specifying a keep-alive interval that is greater than the keep-alive time results in the interval time being adhered to…

Best Answer

After discussion with a super-smart colleague, we think we have figured out what's wrong, but are yet to prove this. What is likely happening is that the keep-alive interval is only taken into account when no keep-alive ACK is received. So after 2 hours, if no ACK was received to this first keep-alive packet, a second packet would be sent after 75 seconds and repeatedly at 75 second intervals until an ACK was received.

It turns out that the reason the interval is taken into account only when it is greater than the keep-alive time is due to the way the Linux keep-alive mechanism works, as described on my other question.

Related Question