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.
More on Connectivity: refused, timed out, no route
`curl: (7) Failed to connect to 10.0.2.15 port 8080: Connection refused`Beginner`curl: (28) Failed to connect to api.internal port 443 after 130001 ms: Connection timed out`Beginner`ssh: connect to host 10.1.4.20 port 22: No route to host`BeginnerService works with `curl localhost:3000` on the box but times out from other hosts.Beginner`ping` works but `curl` to port 80 on the same host times out.Beginner`curl` to a public site works, but `ping 8.8.8.8` shows 100% packet loss.Beginner