While working on a server application that runs on FreeBSD and uses TCP, I noticed that TCP keepalive probes get
sent even though my application explicitly disables SO_KEEPALIVE on TCP sockets.
According to RFC1122 Section 4.2.3.6 (TCP Keep-Alives):
"If keep-alives are included, the application MUST be able to turn
them on or off for each TCP connection, and they MUST default to off."
I found that the tuneable parameter net.inet.tcp.always_keepalive had been enabled (set to 1), and that disabling it would stop the keepalive probes from being sent.
What is the reasoning behind the inclusion of this behaviour in FreeBSD? From what I can tell, Linux and Windows do not have such an option, but FreeBSD and Mac OS X do, so they violate the RFC.
To be more specific, under what circumstance would it make sense to ignore the application's wishes?
This is a straightforward fix in my case as I can disable the option, but I'd like to understand why it's there.
This question shows that Linux behaves according to the RFC.
Best Answer
Rationale for turning keep-alive on by default was given here: https://svnweb.freebsd.org/base?view=revision&revision=47752
Anyway it is better to turn keep-alive off if requested by application, for example (in C):
but it is not easy to fix this.