: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(data-imports): retry postgres connects that fail as "connection is bad" with no detail (#79798)
Tom Owers5437ca0294bd
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.pyindex f3d965064053..771c475dd0af 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py@@ -268,6 +268,17 @@ _CONNECTION_DROPPED_ERROR_SUBSTRINGS = (# retry must catch it. Match the stable prefix + reason and leave pgcat's non-transient reasons# (e.g. BadConfig) to surface."could not get connection from the pool - allserversdown",+ # psycopg's own message when `PQconnectStart` reports the connection BAD before the handshake+ # ever begins and libpq has no server-reported error text to attach (see+ # `psycopg.generators._connect` / `psycopg.pq.misc._clean_error_message`). Unlike every other+ # connect-time failure — which completes enough of the protocol to get an actual message, e.g.+ # "FATAL: password authentication failed" — this one is a purely local failure before any bytes+ # reach the network, typically the worker running out of a local resource needed to open a new+ # socket (file descriptors, ephemeral ports). Transient: the condition clears once the worker's+ # resource pressure eases, so a fresh connect attempt after backoff usually succeeds. The literal+ # "no error details available" suffix is the signal — libpq only omits the message in this local,+ # pre-handshake case, so it never matches a genuine (and permanent) server-reported rejection.+ "connection is bad: no error details available",)# Supavisor (Supabase's connection pooler) doesn't surface a dropped upstream connection with adiff --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 7b6274eae230..2362a94ddc46 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@@ -1697,6 +1697,11 @@ class TestIsConnectionDroppedError:# Supavisor XX000 InternalError_ codes above. Transient — a banned server rejoins on a# passing health check or once its ban expires — so the reconnect must catch it.psycopg.errors.SystemError("could not get connection from the pool - AllServersDown"),+ # psycopg's own message when `PQconnectStart` reports the connection BAD before the+ # handshake begins and libpq has no server-reported error text to attach — a purely+ # local pre-handshake failure (e.g. the worker briefly out of file descriptors), not a+ # server-side rejection. Transient; the reconnect must catch it.+ psycopg.OperationalError("connection is bad: no error details available"),],)def test_connection_dropped_errors_are_detected(self, error):@@ -1729,6 +1734,10 @@ class TestIsConnectionDroppedError:# transient Erlang-tuple "{:error, :econnrefused}" — broadening the match to a plain# "refused" substring would wrongly retry it.psycopg.OperationalError('connection to server at "10.0.0.1", port 5432 failed: Connection refused'),+ # A "connection is bad" failure that *does* carry a server-reported detail is a genuine,+ # permanent rejection — only the "no error details available" variant (a purely local,+ # pre-handshake failure) is transient, so the match must not broaden to the bare prefix.+ psycopg.OperationalError("connection is bad: FATAL: password authentication failed"),],)def test_unrelated_errors_are_not_detected(self, error):