: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): recognize more non-retryable connection rejections (#73144)
Tom Owersaa5c31fa7047
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 5076b4f9ce09..e624871a0df7 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@@ -372,6 +372,13 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa"could not translate host name": None,"timeout expired connection to server at": None,"password authentication failed for user": None,+ # Some providers (observed on a Neon-style pooler) report the same auth rejection without+ # libpq's "for user" wording, putting the role on its own line instead: "password+ # authentication failed\nuser \"<role>\"". The key above requires "for user" right after+ # "failed", so it doesn't substring-match this variant and Temporal keeps retrying a+ # credential mismatch only the customer can fix. Match the stable, wording-independent+ # fragment shared by both forms.+ "password authentication failed": None,# AWS RDS Proxy reports bad credentials with its own wording instead of PostgreSQL's# "password authentication failed for user" — it validates against Secrets Manager and# returns "The password that was provided for the role <role> is wrong." None of the@@ -410,7 +417,25 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa# Marking it non-retryable would permanently disable syncs on a transient blip. A# genuinely unsupported-SSL source fails at connect time with a different message and is# caught via "SSLRequiredError" / "SSL/TLS connection is required".- "Address not in tenant allow_list": None,+ # A Neon-style proxy rejects the connection because PostHog's egress IP isn't on the+ # project's configured IP allow list (EADDRNOTALLOWED). Deterministic until the customer+ # updates the allow list, so retrying just re-hits the same rejection. NB: the raw message+ # lowercases "address" ("... FATAL: (EADDRNOTALLOWED) address not in tenant allow_list:+ # ..."), unlike the capitalized key this replaced, which never matched production traffic.+ "address not in tenant allow_list": (+ "Your database provider rejected the connection because PostHog's IP address is not on "+ 'its configured allow list ("address not in tenant allow_list"). Add PostHog\'s egress IP '+ "addresses to your database provider's IP allow list, then re-enable the sync."+ ),+ # A Neon-style proxy rejects the connection for a specific branch/compute endpoint —+ # observed when the branch is archived, suspended, or otherwise restricted from external+ # connections. Deterministic until the customer changes the branch's connection settings.+ "connection not allowed for branch": (+ "Your database provider rejected the connection for this branch or compute endpoint "+ '("connection not allowed for branch"). This usually means the branch is archived, '+ "suspended, or restricted from external connections. Check your database provider's "+ "dashboard for this branch's connection settings, then re-enable the sync."+ ),"FATAL: no such database": None,"does not exist": None,"timestamp too small": None,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 06ecec1cbbae..a16bfac3ece2 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@@ -696,6 +696,79 @@ class TestPostgresSourceNonRetryableErrors:assert friendly, "Missing pooler tenant identifier error should surface an actionable message"assert "project ref" in friendly[0]+ @pytest.mark.parametrize(+ "error_msg",+ [+ # Real production wording (a Neon-style proxy) lowercases "address", unlike the+ # capitalized key this replaced, which never matched production traffic. Host/IP, port,+ # and the allow-listed IP tuple are volatile and excluded from the match.+ 'connection failed: connection to server at "203.0.113.10", port 5432 failed: FATAL: '+ "(EADDRNOTALLOWED) address not in tenant allow_list: {203, 0, 113, 99}\n"+ 'connection to server at "203.0.113.10", port 5432 failed: FATAL: (ESSLREQUIRED) SSL '+ "connection is required for user: postgres",+ ],+ )+ def test_ip_not_in_tenant_allow_list_is_non_retryable(self, source, error_msg):+ non_retryable = source.get_non_retryable_errors()+ assert "address not in tenant allow_list" in non_retryable+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())+ assert is_non_retryable, f"IP-not-in-allow-list error should be non-retryable: {error_msg}"++ def test_ip_not_in_tenant_allow_list_returns_friendly_message(self, source):+ non_retryable = source.get_non_retryable_errors()+ error_msg = (+ 'connection failed: connection to server at "203.0.113.10", port 5432 failed: FATAL: '+ "(EADDRNOTALLOWED) address not in tenant allow_list: {203, 0, 113, 99}"+ )+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]+ assert friendly, "IP-not-in-allow-list error should surface an actionable message"+ assert "allow list" in friendly[0]++ @pytest.mark.parametrize(+ "error_msg",+ [+ # A Neon-style proxy rejects the connection for a specific branch before the SSL-required+ # fallback attempt is even tried. Host/IP, port, and the branch id are volatile.+ 'connection failed: connection to server at "203.0.113.20", port 6432 failed: FATAL: '+ "connection not allowed for branch abc123xyz\n"+ 'connection to server at "203.0.113.20", port 6432 failed: FATAL: SSL/TLS required',+ ],+ )+ def test_branch_connection_not_allowed_is_non_retryable(self, source, error_msg):+ non_retryable = source.get_non_retryable_errors()+ assert "connection not allowed for branch" in non_retryable+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())+ assert is_non_retryable, f"Branch connection restriction error should be non-retryable: {error_msg}"++ def test_branch_connection_not_allowed_returns_friendly_message(self, source):+ non_retryable = source.get_non_retryable_errors()+ error_msg = (+ 'connection failed: connection to server at "203.0.113.20", port 6432 failed: FATAL: '+ "connection not allowed for branch abc123xyz"+ )+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]+ assert friendly, "Branch connection restriction error should surface an actionable message"+ assert "branch" in friendly[0]++ @pytest.mark.parametrize(+ "error_msg",+ [+ # Observed on a Neon-style pooler: the role is reported on its own line instead of+ # libpq's "for user" wording, so it doesn't substring-match "password authentication+ # failed for user". Host/IP, port, and the role id are volatile.+ 'connection failed: connection to server at "203.0.113.30", port 5432 failed: FATAL: '+ 'password authentication failed\nuser "11111111-2222-3333-4444-555555555555"',+ ],+ )+ def test_password_authentication_failed_without_for_user_wording_is_non_retryable(self, source, error_msg):+ non_retryable = source.get_non_retryable_errors()+ assert "password authentication failed" in non_retryable+ assert "password authentication failed for user" not in error_msg+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())+ assert is_non_retryable, (+ f"Password auth failure without 'for user' wording should be non-retryable: {error_msg}"+ )+@pytest.mark.parametrize("error_msg",[