Interview Prep/Networking/Connectivity: refused, timed out, no route

A TCP connection establishes, but the first request after it has sat idle for an hour hangs and eventually times out.

AdvancedTroubleshootingConnectivity: refused, timed out, no route
Answer

Likely causes → A stateful middlebox (NAT gateway, firewall, LB) evicted the idle flow. The client still thinks the connection exists, sends data, and packets are dropped silently. AWS NAT gateway idle timeout is 350 s; many firewalls use 3600 s.

Diagnose →

ss -tno state established '( dport = :5432 )'   # timer:(keepalive,...) shows if keepalives are on
sysctl net.ipv4.tcp_keepalive_time

Fix → Enable TCP keepalive at an interval shorter than the shortest idle timeout (e.g. tcp_keepalive_time=300, or keepalives_idle=60 in the libpq connection string). Configure connection pools to validate or recycle idle connections.

Prevent → Document idle timeouts of every hop and set pool max_idle_time below them.

All Networking questions Roadmap: Networking for DevOps

More on Connectivity: refused, timed out, no route