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 Neon IP allow-list and blocked-network rejections (#106569)

Tom Owers78b1b0aac114
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/errors.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/errors.py
index 818be0f39d63..7aa339bee112 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/errors.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/errors.py
@@ -47,6 +47,15 @@ _HOST_UNREACHABLE_MARKERS = (
"enetunreach",
)
+# A managed provider (observed on Neon) refuses PostHog's IP address, either because it isn't on the
+# project's IP allow list or because the project blocks public access. Deterministic until the
+# customer changes that network policy. Mirrors the non-retryable treatment on the batch path
+# (PostgresSource.get_non_retryable_errors).
+_IP_NOT_ALLOWED_MARKERS = (
+ "is not allowed to connect to this endpoint",
+ "access this endpoint from a blocked network",
+)
+
# A managed provider (observed on Neon) blocks the connection once the account or project has
# exceeded a usage quota, reporting a plain libpq ERROR rather than a connection failure. Mirrors
# the non-retryable treatment on the batch path (PostgresSource.get_non_retryable_errors's
@@ -125,6 +134,8 @@ def classify_postgres_cdc_error(exc: BaseException) -> CDCErrorCategory | None:
return CDCErrorCategory.PERMISSION_DENIED
if isinstance(exc, psycopg.OperationalError):
+ if any(marker in message for marker in _IP_NOT_ALLOWED_MARKERS):
+ return CDCErrorCategory.HOST_UNREACHABLE
if any(marker in message for marker in _SSL_REQUIRED_MARKERS):
return CDCErrorCategory.SSL_REQUIRED
if any(marker in message for marker in _HOST_UNREACHABLE_MARKERS):
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_errors.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_errors.py
index 57e091198c15..d41fcc467a26 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_errors.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_errors.py
@@ -79,6 +79,22 @@ class TestClassifyPostgresCDCError:
),
CDCErrorCategory.HOST_UNREACHABLE,
),
+ (
+ "provider_ip_allow_list_rejection_is_non_retryable_host",
+ psycopg.OperationalError(
+ "connection to server at example.invalid, port 5432 failed: ERROR: This IP address "
+ "198.51.100.7 is not allowed to connect to this endpoint."
+ ),
+ CDCErrorCategory.HOST_UNREACHABLE,
+ ),
+ (
+ "provider_blocked_network_rejection_is_non_retryable_host",
+ psycopg.OperationalError(
+ "connection to server at example.invalid, port 5432 failed: ERROR: This connection is "
+ "trying to access this endpoint from a blocked network."
+ ),
+ CDCErrorCategory.HOST_UNREACHABLE,
+ ),
(
"database_host_not_allowed_is_non_retryable_host",
HostNotAllowedError("Database host not allowed: resolves to a private address"),
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 1307cf233c3c..73702169ba02 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
@@ -649,6 +649,18 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa
'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."
),
+ # Neon words its own IP allow list rejection differently from the Supavisor key above
+ # ("This IP address <ip> is not allowed to connect to this endpoint"), and rejects a
+ # project that blocks public access with "... from a blocked network". Both are the
+ # customer's network policy, so every retry re-hits them until they change it.
+ "is not allowed to connect to this endpoint": (
+ "Your database provider rejected the connection because PostHog's IP address isn't on its "
+ "IP allow list. Add PostHog's egress IP addresses to that allow list, then re-enable the sync."
+ ),
+ "access this endpoint from a blocked network": (
+ "Your database provider blocks connections from the public internet, so PostHog can't "
+ "connect. Allow public access for PostHog's IP addresses, 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.
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 2276f376b16f..dbbd87dfbd1f 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
@@ -1147,6 +1147,35 @@ class TestPostgresSourceNonRetryableErrors:
assert friendly, "IP-not-in-allow-list error should surface an actionable message"
assert "allow list" in friendly[0]
+ @pytest.mark.parametrize(
+ "error_msg,expected_fragment",
+ [
+ (
+ 'connection failed: connection to server at "203.0.113.30", port 5432 failed: ERROR: This IP '
+ "address 198.51.100.7 is not allowed to connect to this endpoint.\n"
+ 'connection to server at "203.0.113.30", port 5432 failed: ERROR: connection is insecure',
+ "allow list",
+ ),
+ (
+ 'connection failed: connection to server at "203.0.113.31", port 5432 failed: ERROR: This '
+ "connection is trying to access this endpoint from a blocked network.\n"
+ 'connection to server at "203.0.113.31", port 5432 failed: ERROR: connection is insecure',
+ "public access",
+ ),
+ ],
+ )
+ def test_neon_network_policy_rejection_is_non_retryable_with_friendly_message(
+ self, source, error_msg, expected_fragment
+ ):
+ non_retryable = source.get_non_retryable_errors()
+ friendly = [
+ reason
+ for pattern, reason in non_retryable.items()
+ if error_message_matches(error_msg, [pattern]) and reason
+ ]
+ assert friendly, f"Network policy rejection should be non-retryable with an actionable message: {error_msg}"
+ assert expected_fragment in friendly[0]
+
@pytest.mark.parametrize(
"error_msg",
[