Operating Systems (both Windoows and Linux) have default TCP Keepalive values, but TCP Keepalive must be enabled on the socket in order for Keepalive to be used. (Windows Reference, Linux Reference)
This setting is achieved by calling socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true)
Should we always enable TCP Keepalive on the Socket? Or only if the Keepalive connection string parameter is set? I'm partial to always enabling it due to the nature of pooled connections potentially being idle.
Overriding System-Wide settings with Per-Socket settings
There are 3 settings that can be overridden, outlined here. Example:
The first two parameters are expressed in seconds, and the last is the pure number. This means that the keepalive routines wait for two hours (7200 secs) before sending the first keepalive probe, and then resend it every 75 seconds. If no ACK response is received for nine consecutive times, the connection is marked as broken.