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): treat CDC host-unreachable network errors as non-retryable (#66425)

Tom Owers97946a12eb88
diff --git a/products/warehouse_sources/backend/temporal/data_imports/cdc/errors.py b/products/warehouse_sources/backend/temporal/data_imports/cdc/errors.py
index 2e15c949a395..eaaf543898e8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/cdc/errors.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/cdc/errors.py
@@ -26,6 +26,7 @@ class CDCErrorCategory(enum.StrEnum):
AUTH_FAILED = "auth_failed"
SSL_REQUIRED = "ssl_required"
CONNECTION_FAILED = "connection_failed"
+ HOST_UNREACHABLE = "host_unreachable"
SLOT_MISSING = "slot_missing"
PUBLICATION_MISSING = "publication_missing"
SLOT_IN_USE = "slot_in_use"
@@ -79,6 +80,13 @@ _CATEGORY_DEFAULTS: dict[CDCErrorCategory, tuple[str, bool]] = {
"check that the database is reachable and accepting connections.",
True,
),
+ CDCErrorCategory.HOST_UNREACHABLE: (
+ "PostHog has no network route to the source database host, so it can't be reached. Check "
+ "that the host and port are correct and reachable from the public internet (PostHog's IP "
+ "addresses allowed through, and the host not resolving to a private or unreachable "
+ "address), then re-enable change data capture.",
+ False,
+ ),
CDCErrorCategory.SLOT_MISSING: (
"The replication slot no longer exists on the source database, so changes can no longer be "
"read. Disable and re-enable change data capture to recreate it and re-sync.",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_errors.py b/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_errors.py
index b4f629ba22f1..c300780b6ef6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_errors.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_errors.py
@@ -32,6 +32,7 @@ class TestCDCErrorInfo:
(CDCErrorCategory.AUTH_FAILED, False),
(CDCErrorCategory.SSL_REQUIRED, False),
(CDCErrorCategory.CONNECTION_FAILED, True),
+ (CDCErrorCategory.HOST_UNREACHABLE, False),
(CDCErrorCategory.SLOT_MISSING, False),
(CDCErrorCategory.PUBLICATION_MISSING, False),
(CDCErrorCategory.SLOT_IN_USE, True),
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 beb2ddfea889..fd38a407d149 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
@@ -28,6 +28,17 @@ _AUTH_MARKERS = (
"no password supplied",
)
+# Routing failures (ENETUNREACH / EHOSTUNREACH): there is no route to the host's network at all,
+# so the connection never leaves PostHog. Unlike a refused or reset connection — where the host is
+# 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).
+_HOST_UNREACHABLE_MARKERS = (
+ "network is unreachable",
+ "no route to host",
+)
+
def classify_postgres_cdc_error(exc: BaseException) -> CDCErrorCategory | None:
"""Classify a single Postgres exception into a ``CDCErrorCategory``.
@@ -69,6 +80,8 @@ def classify_postgres_cdc_error(exc: BaseException) -> CDCErrorCategory | None:
if isinstance(exc, psycopg.OperationalError):
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):
+ return CDCErrorCategory.HOST_UNREACHABLE
return CDCErrorCategory.CONNECTION_FAILED
return None
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 375d0b1da711..3bf4781c2864 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
@@ -42,6 +42,18 @@ class TestClassifyPostgresCDCError:
psycopg.OperationalError("connection to server at localhost, port 5432 failed: Connection refused"),
CDCErrorCategory.CONNECTION_FAILED,
),
+ (
+ "network_unreachable_is_non_retryable_host",
+ psycopg.OperationalError(
+ 'connection to server at "2001:db8::1", port 5432 failed: Network is unreachable'
+ ),
+ CDCErrorCategory.HOST_UNREACHABLE,
+ ),
+ (
+ "no_route_to_host_is_non_retryable_host",
+ psycopg.OperationalError("connection to server at example.invalid, port 5432 failed: No route to host"),
+ CDCErrorCategory.HOST_UNREACHABLE,
+ ),
(
"slot_missing",
psycopg.errors.UndefinedObject('replication slot "posthog_slot" does not exist'),