: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): stop blaming idle connections for a drop while connecting (#115313)
Tom Owers2593bff49fce
diff --git a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.pyindex d4f6f6e5f9a4..d2e1a47ac1ff 100644--- a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py+++ b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py@@ -265,6 +265,17 @@ TRANSIENT_SOURCE_CONNECTION_MESSAGE = ("reachable and doesn't drop idle connections; the next sync runs on schedule.")+# libpq prefixes a failure with "connection to server at <host>, port <port> failed:" only while it+# sets the connection up. A drop there never reached an idle connection, so the generic copy points+# the customer at the wrong cause. A server that accepts the TCP connection and then closes it+# during startup is usually down, or an allowlist in front of it rejects PostHog's addresses.+LIBPQ_CONNECT_FAILURE_MARKER = "connection to server at"++TRANSIENT_CONNECT_DROPPED_MESSAGE = (+ "Your database closed the connection while PostHog was connecting. Check that it's running and "+ "allows PostHog's IP addresses; the next sync runs on schedule."+)+TRANSIENT_POOLER_MESSAGE = ("Your database's connection pooler couldn't reach your database and refused the connection. ""Check that the database is running; the next sync runs on schedule."@@ -465,7 +476,7 @@ def _transient_error_message(internal_error: str) -> str | None:First match wins, mirroring how the non-retryable path picks its friendly message."""- return next(+ message = next((messagefor pattern, message in Transient_Error_Messages.items()@@ -473,6 +484,11 @@ def _transient_error_message(internal_error: str) -> str | None:),None,)+ if message == TRANSIENT_SOURCE_CONNECTION_MESSAGE and error_message_matches(+ internal_error, [LIBPQ_CONNECT_FAILURE_MARKER]+ ):+ return TRANSIENT_CONNECT_DROPPED_MESSAGE+ return messagedef _fail_stale_running_schema(diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py b/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.pyindex 5135f6b419a8..5846c9dcb3cf 100644--- a/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py@@ -21,6 +21,7 @@ from products.warehouse_sources.backend.temporal.data_imports.external_data_jobRAILWAY_PROXY_CONNECTION_MESSAGE,SYNC_RUN_STALLED_MESSAGE,SYNC_RUN_TOO_LONG_MESSAGE,+ TRANSIENT_CONNECT_DROPPED_MESSAGE,TRANSIENT_EGRESS_MESSAGE,TRANSIENT_POOLER_MESSAGE,TRANSIENT_SOURCE_CONNECTION_MESSAGE,@@ -355,10 +356,17 @@ def test_read_only_transaction_disables_the_schema_only_when_the_source_raised_i# psycopg's connect-time wrapper around a dropped TLS session. The address is a# documentation-reserved one, standing in for the host the driver echoes back.(- "postgres_ssl_drop",+ "postgres_ssl_drop_at_connect",ExternalDataSourceType.POSTGRES,'connection failed: connection to server at "198.51.100.7", port 5432 failed: '"SSL SYSCALL error: EOF detected",+ TRANSIENT_CONNECT_DROPPED_MESSAGE,+ ),+ # The same drop on an established connection, which keeps the idle-connection copy.+ (+ "postgres_server_closed_mid_stream",+ ExternalDataSourceType.POSTGRES,+ "consuming input failed: server closed the connection unexpectedly",TRANSIENT_SOURCE_CONNECTION_MESSAGE,),# A connect-time capacity refusal. The generic map has no entry for it, so the Postgres