: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): stop reporting admin-shutdown connection drops as defects (#73426)
Tom Owersa7fa9f415b4d
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 1590e8dca3ba..f81380b43eae 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@@ -717,6 +717,17 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa),}+ def get_retryable_errors(self) -> set[str]:+ # `get_rows` already retries a mid-stream drop in-process (reconnect, or fall back to+ # offset chunking) — see `_CONNECTION_DROPPED_ERROR_SUBSTRINGS` in postgres.py. It only+ # reaches here once that in-process handling gives up (e.g. a full-table scan can't safely+ # resume once rows have been yielded, since OFFSET has no stable ORDER BY to resume from).+ # Temporal then retries the whole activity and the failure is transient and+ # self-recovering, so classify it here too — otherwise `_handle_import_error` logs it at+ # `exception` on every occurrence, flooding error tracking with a self-recovering failure+ # (e.g. a cloud provider terminating a backend for maintenance or failover).+ return {"terminating connection due to"}+def reconcile_schema_metadata(self,source: "ExternalDataSource",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.pyindex 0c50b22e3b09..901a904deae7 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@@ -1103,6 +1103,37 @@ class TestPostgresSourceNonRetryableErrors:assert is_non_retryable, f"SSH handshake EOF should be non-retryable: {_SSH_HANDSHAKE_EOF_ERROR}"+class TestPostgresSourceRetryableErrors:+ @pytest.fixture+ def source(self):+ return PostgresSource()++ @pytest.mark.parametrize(+ "error_msg",+ [+ # SQLSTATE 57P01: a DBA (or a cloud provider's maintenance/failover automation) killed+ # our backend. `get_rows`'s in-process reconnect/offset-chunking already retries this+ # mid-stream; it only reaches `_handle_import_error` once that resume is unsafe (a+ # full-table scan with rows already yielded) or its retry budget is exhausted.+ "terminating connection due to administrator command",+ "OperationalError: terminating connection due to administrator command",+ ],+ )+ def test_admin_shutdown_is_classified_retryable(self, source, error_msg):+ retryable = source.get_retryable_errors()+ is_retryable = any(pattern in error_msg for pattern in retryable)+ assert is_retryable, f"Admin-shutdown error should be classified retryable: {error_msg}"++ def test_admin_shutdown_is_not_also_non_retryable(self, source):+ # Guards against the two classifications disagreeing — `_handle_import_error` checks+ # non-retryable first, so if this ever matched both, it would stop the sync instead of+ # retrying the activity.+ error_msg = "terminating connection due to administrator command"+ non_retryable = source.get_non_retryable_errors()+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())+ assert not is_non_retryable, f"Admin-shutdown error should not be non-retryable: {error_msg}"++def _raise_eof() -> None:# Indirection so the `yield` below stays reachable under mypy's warn_unreachable — at runtime# this raises before the generator yields, standing in for paramiko's handshake EOFError.