: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): surface actionable message for an unreachable host (#93193)
Tom Owers0f2202827e75
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 855916028b22..de491b1ab24e 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@@ -562,7 +562,13 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa# database host doesn't resolve to an address — a config/DNS issue on their side that# retrying won't fix."No address associated with hostname": _DNS_RESOLUTION_ERROR,- "Network is unreachable": None,+ # A resolved-but-unroutable host (ENETUNREACH) — an IPv6-only host PostHog can't reach+ # over IPv4, or a firewall dropping our egress IPs. Already non-retryable, but the bare+ # driver text ("connection to server at <host> ... Network is unreachable") gives the+ # customer nothing to act on and echoes their host/IP back into `latest_error`. Surface+ # the same actionable guidance the validate path and the Supavisor `:enetunreach` twin+ # above already use.+ "Network is unreachable": _HOST_UNREACHABLE_ERROR,# `InsufficientPrivilege` is the psycopg exception class name. It only appears once# Temporal wraps the activity failure (`ApplicationError` stringifies as# "InsufficientPrivilege: ..."), so it matches at the workflow layer but NOT in the@@ -635,7 +641,10 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa),"InvalidObjectDefinition": None,"Connection refused": None,- "No route to host": None,+ # EHOSTUNREACH — the routing sibling of "Network is unreachable" above. Same+ # unroutable-host class (IPv6-only host, or a firewall dropping our IPs), so surface the+ # same actionable guidance instead of the raw driver text (which echoes the host/IP).+ "No route to host": _HOST_UNREACHABLE_ERROR,# The OS-level TCP connect() timing out (strerror(ETIMEDOUT)) instead of getting an# immediate refusal or unreachable-route response. Same connect-time host-reachability# class as its two siblings above — usually a non-routable host (e.g. a private RDSdiff --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 092aaaea41b2..49f0473ddfbb 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@@ -532,6 +532,31 @@ class TestPostgresSourceNonRetryableErrors:assert matches[0] is not None, "DNS resolution failure must surface an actionable message, not raw driver text"assert "resolve" in matches[0].lower()+ @pytest.mark.parametrize(+ "error_msg",+ [+ # ENETUNREACH — a resolved-but-unroutable host (IPv6-only, or a firewall dropping our+ # IPs). Host/IP and port are invented, not real customer values.+ 'connection is bad: connection to server at "2600:1f18::1", port 5432 failed: Network is unreachable',+ # EHOSTUNREACH — the routing sibling; libpq may append the "Is the server running..." hint.+ 'connection failed: connection to server at "203.0.113.7", port 5432 failed: No route to host',+ ],+ )+ def test_unreachable_host_surfaces_actionable_message(self, source, error_msg):+ # A resolved-but-unroutable host stays non-retryable, but the sync path must surface the same+ # IPv4/firewall guidance the validate path gives rather than the raw driver text (which+ # echoes the customer's host/IP into latest_error). Mirror the finalizer's first-match+ # selection so a reorder that shadows it with an earlier None key, or a revert back to None,+ # is caught.+ matches = [+ friendly+ for pattern, friendly in source.get_non_retryable_errors().items()+ if error_message_matches(error_msg, [pattern])+ ]+ assert matches, f"an unreachable host must be classified non-retryable: {error_msg}"+ assert matches[0] is not None, "an unreachable host must surface an actionable message, not raw driver text"+ assert "IPv4" in matches[0]+@pytest.mark.parametrize("error_msg",[