What TCP keepalive settings matter for long-lived connections through NAT/LBs?
AdvancedProductionLogs, Limits & High-Traffic Tuning
Answer
Cloud NAT gateways and load balancers drop idle flows silently (AWS NAT Gateway after 350 s idle; ALB/NLB have their own idle timeouts). The Linux default net.ipv4.tcp_keepalive_time=7200 (2 hours) is far too long, so idle DB connections appear alive but are dead. Lower it (e.g. 300 s with tcp_keepalive_intvl=30, tcp_keepalive_probes=5), and make sure the app enables SO_KEEPALIVE (most DB drivers have an option) or uses application-level pings.
More on Logs, Limits & High-Traffic Tuning
How does log management work on a modern Linux server?BeginnerWhy centralize logs instead of reading them on each server?BeginnerWrite a logrotate config for an application log.BeginnerWhat is the difference between `copytruncate` and `create` + postrotate signal?IntermediateLogs rotated but disk usage did not drop. Why?IntermediateHow often does logrotate run, and why does `maxsize` sometimes not trigger in time?Intermediate