: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(postgres): actionable message for connect-time connection timeouts (#82533)
Tom Owersaae9cb566496
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.pyindex cc651418935c..abb1382b3497 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@@ -536,7 +536,18 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa"Connection refused": None,"No route to host": None,"password authentication failed connection": None,- "connection timeout expired": None,+ # psycopg raises ConnectionTimeout ("connection timeout expired") only while establishing+ # a connection. The read path retries it in-process first (see+ # `_is_dropped_or_connect_timeout`); reaching here means every reconnect timed out, i.e. a+ # persistently unreachable host — usually a firewall dropping PostHog's egress IPs, an+ # IPv6-only host, or a wrong host/port. Stays non-retryable; give the actionable guidance+ # the bare driver text lacks (mirrors the validate-path message for "timeout expired").+ "connection timeout expired": (+ "PostHog couldn't connect to your database before the connection timed out. Check that "+ "the database is reachable from the public internet and that PostHog's egress IP "+ "addresses are allowed through your firewall. For a database that can't be exposed "+ "publicly, use the SSH tunnel option, then re-enable the sync."+ ),# TLS ALPN alert (RFC 7301 "no_application_protocol", alert 120) sent by the server# during the TLS handshake. libpq (Postgres 17+) offers the "postgresql" ALPN protocol;# an endpoint that negotiates ALPN but doesn't accept it rejects the handshake outright.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.pyindex cfe035c46288..9620e63cc152 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@@ -425,6 +425,21 @@ class TestPostgresSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable, f"Permanent error should be non-retryable: {error_msg}"+ def test_connect_timeout_surfaces_actionable_message(self, source):+ # A persistently timing-out connect stays non-retryable, but must surface firewall/reachability+ # guidance rather than the bare "connection timeout expired" driver text. Mirror the finalizer's+ # first-match selection (external_data_job.py) so a future reorder that shadows it with an+ # earlier None-valued timeout key is caught.+ error_msg = "connection timeout expired"+ matches = [+ friendly+ for pattern, friendly in source.get_non_retryable_errors().items()+ if error_message_matches(error_msg, [pattern])+ ]+ assert matches, "connect timeout must be classified non-retryable"+ assert matches[0] is not None, "connect timeout must surface an actionable message, not raw driver text"+ assert "firewall" in matches[0].lower()+@pytest.mark.parametrize("error_msg",[