3

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...

1

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.

0

Indeed, from the documentation :

tcp_keepalive_time

the interval between the last data packet sent (simple ACKs are not considered data) and the first keepalive probe; after the connection is marked to need keepalive, this counter is not used any further

tcp_keepalive_intvl

the interval between subsequential keepalive probes, regardless of what the connection has exchanged in the meantime

tcp_keepalive_probes

the number of unacknowledged probes to send before considering the connection dead and notifying the application layer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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