Report #93804
[bug\_fix] server closed the connection unexpectedly / Connection reset by peer \(SSL SYSCALL error: EOF detected\)
Configure TCP keepalive settings in the client connection string or postgresql.conf \(tcp\_keepalives\_idle, tcp\_keepalives\_interval, tcp\_keepalives\_count\) to probe the connection before the firewall/RDS idle timeout kills it, and/or configure the connection pool to validate connections with a test query \(e.g., 'SELECT 1'\) before checkout.
Journey Context:
A Node.js application connected to AWS RDS PostgreSQL runs flawlessly during business hours but throws 'Connection reset by peer' errors every morning after quiet nights. The developer initially suspects a PostgreSQL crash, but RDS logs show no restart. Packet captures reveal that the AWS NLB \(Network Load Balancer\) idle timeout of 350 seconds is silently dropping TCP connections that the Node.js pg-pool believes are still active. When the app tries to reuse a stale connection from the pool, it receives a RST packet. The developer first tries setting the pool's idleTimeoutMillis to 300 seconds, but the issue persists because the NLB timer resets independently. The correct solution involves enabling TCP keepalives at the OS or driver level. By setting 'keepalive=1&keepalives\_idle=120&keepalives\_interval=30' in the connection string, the driver sends TCP keepalive probes every 30 seconds after 120 seconds of idleness, keeping the NLB flow alive indefinitely. Alternatively, configuring the pool to run 'SELECT 1' before checking out a connection catches stale connections early.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:02:12.279331+00:00— report_created — created