Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(postgres): stop retrying a TCP connect timeout to an unreachable host (#87512)

Tom Owers338cee032221
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py
index 8e1c86aa0257..14d6995088bc 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py
@@ -577,6 +577,12 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa
"InvalidObjectDefinition": None,
"Connection refused": None,
"No route to host": None,
+ # The OS-level TCP connect() timing out (strerror(ETIMEDOUT)) instead of getting an
+ # immediate refusal or unreachable-route response. Same connect-time host-reachability
+ # class as its two siblings above — usually a non-routable host (e.g. a private RDS
+ # endpoint) or a firewall silently dropping PostHog's egress IPs — and won't change on
+ # retry until the customer fixes the network path.
+ "Connection timed out": None,
"password authentication failed connection": None,
# psycopg raises ConnectionTimeout ("connection timeout expired") only while establishing
# a connection. The read path retries it in-process first (see
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py
index b0903dbd05bb..5ed01bfe3854 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py
@@ -400,6 +400,10 @@ class TestPostgresSourceNonRetryableErrors:
[
'psycopg2.OperationalError: could not connect to server: Connection refused\n\tIs the server running on host "10.0.0.1" and accepting TCP/IP connections on port 5432?',
'psycopg2.OperationalError: could not connect to server: No route to host\n\tIs the server running on host "10.0.0.1"?',
+ # The OS-level TCP connect() timeout (ETIMEDOUT) — no response at all, as opposed to the
+ # immediate rejection of "Connection refused". Observed against a private RDS endpoint
+ # PostHog can't route to.
+ 'could not connect to server "some_server"\nDETAIL: connection to server at "10.0.5.177", port 5432 failed: Connection timed out\n\tIs the server running on that host and accepting TCP/IP connections?',
'could not translate host name "bad-hostname.example.com" to address: Name or service not known',
'FATAL: password authentication failed for user "myuser"',
'FATAL: no such database "nonexistent_db"',