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): map Supavisor ENETUNREACH to a non-retryable host-unreachable error (#88343)

Tom Owers57c6148b461a
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 c6d9abe44c3a..c8bdc063d730 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
@@ -34,10 +34,13 @@ _AUTH_MARKERS = (
# reachable and the failure is plausibly transient — these are deterministic for the configured
# host (e.g. it resolves to a private or otherwise non-routable address, such as an IPv6 address
# PostHog can't route to), so retrying re-hits the same wall. Mirrors the non-retryable treatment
-# on the batch path (PostgresSource.get_non_retryable_errors).
+# on the batch path (PostgresSource.get_non_retryable_errors). "enetunreach" is Supabase Supavisor's
+# erlang-tuple wording of the same condition ("{:error, :enetunreach}"), which never contains the
+# libpq phrasing above.
_HOST_UNREACHABLE_MARKERS = (
"network is unreachable",
"no route to host",
+ "enetunreach",
)
# sshtunnel raises BaseSSHTunnelForwarderError("Could not establish session to SSH gateway") when it
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 564b2be302fd..966a9204a67d 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
@@ -55,6 +55,16 @@ class TestClassifyPostgresCDCError:
psycopg.OperationalError("connection to server at example.invalid, port 5432 failed: No route to host"),
CDCErrorCategory.HOST_UNREACHABLE,
),
+ (
+ # Supavisor reports the same routing failure with its erlang-tuple wording, which
+ # never contains the libpq phrases above.
+ "supavisor_enetunreach_is_non_retryable_host",
+ psycopg.OperationalError(
+ "connection to server at example.invalid, port 5432 failed: FATAL: "
+ "Failed to connect to database: {:error, :enetunreach}"
+ ),
+ CDCErrorCategory.HOST_UNREACHABLE,
+ ),
(
"slot_missing",
psycopg.errors.UndefinedObject('replication slot "posthog_slot" does not exist'),
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 14d6995088bc..61972a6086d2 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
@@ -361,6 +361,15 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa
'("nxdomain"). This usually means the database project is paused or deleted. Check '
"that your database is active, then re-enable the sync."
),
+ # Supabase's Supavisor pooler reports a routing failure to its upstream backend as
+ # "FATAL: Failed to connect to database: {:error, :enetunreach}" — Erlang's wording for
+ # ENETUNREACH, the same OS condition libpq surfaces as "Network is unreachable" (handled
+ # below). Unlike the sibling ":etimedout"/":econnrefused" tuples in
+ # `_CONNECTION_DROPPED_ERROR_SUBSTRINGS` — a transient blip reaching a backend that's up —
+ # there's no route to the backend's network at all, which is deterministic for the
+ # configured host (an IPv6-only backend PostHog can't route to, or a firewall dropping our
+ # IPs), so retrying re-hits the same wall. Match the stable erlang-tuple fragment.
+ "{:error, :enetunreach}": _HOST_UNREACHABLE_ERROR,
# Supabase/Supavisor poolers reject a connection that carries no tenant identifier with
# "FATAL: (ENOIDENTIFIER) no tenant identifier provided (external_id or sni_hostname
# required)". The shared regional pooler host (e.g. aws-0-<region>.pooler.supabase.com)
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 5ed01bfe3854..4f971abf6a37 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
@@ -758,6 +758,22 @@ class TestPostgresSourceNonRetryableErrors:
is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
assert is_non_retryable, f"Supavisor nxdomain pooler DNS failure should be non-retryable: {error_msg}"
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ # Supavisor reports ENETUNREACH (no route to the upstream backend's network) with its
+ # erlang-tuple wording, which never contains libpq's "Network is unreachable". Distinct
+ # from the sibling ":etimedout"/":econnrefused" tuples, which are transient and retryable.
+ 'connection failed: connection to server at "203.0.113.10", port 5432 failed: FATAL: Failed to connect to database: {:error, :enetunreach}',
+ 'connection failed: connection to server at "203.0.113.20", port 6543 failed: FATAL: Failed to connect to database: {:error, :enetunreach}',
+ ],
+ )
+ def test_supavisor_enetunreach_pooler_routing_failure_is_non_retryable(self, source, error_msg):
+ non_retryable = source.get_non_retryable_errors()
+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]
+ assert friendly, f"Supavisor enetunreach routing failure should surface an actionable message: {error_msg}"
+ assert "IPv4" in friendly[0]
+
@pytest.mark.parametrize(
"error_msg",
[