Loose Ends

TCP keepalive defaults and half-dead connections

02 September 2026

If a peer disappears without closing the connection, your side may wait for a very long time. The Linux default makes this easy to reproduce.

sysctl net.ipv4.tcp_keepalive_time
net.ipv4.tcp_keepalive_time = 7200

Keepalive probes start only after two hours of silence, then repeat a few times before the connection is declared dead. For a database client or a long-lived API connection that is far too slow.

The fix is usually to set keepalive on the socket in the application, with values of tens of seconds, rather than changing the system default for every program. Check the client library documentation first, since many expose these options.