: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 exhausted connection-limit retries as error-tracking noise (#78494)
Tom Owers3fc4f60016bc
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 1c580f09bcce..acb723858a73 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@@ -41,6 +41,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.postgres.cdrop_slot_and_publication,)from products.warehouse_sources.backend.temporal.data_imports.sources.postgres.postgres import (+ _CONNECTION_LIMIT_ERROR_SUBSTRINGS,_SSH_HANDSHAKE_EOF_ERROR,XMIN_AS_INCREMENTAL_FIELD_ERROR,PostgresImplementation,@@ -786,7 +787,17 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa# offset-chunking reconnect also retries in-process (`_SERVER_STARTING_UP_ERROR_SUBSTRINGS`# in postgres.py) — this is the same whole-activity-retry fallback for when that budget is# exhausted (e.g. a longer maintenance window).- return {"terminating connection due to", "the database system is shutting down"}+ #+ # `_CONNECTION_LIMIT_ERROR_SUBSTRINGS` (e.g. "remaining connection slots are reserved") is a+ # connect-time capacity refusal already retried in-process by `_connect_with_dropped_retry` /+ # `_is_dropped_or_connection_limit`. A slot frees the moment another connection closes, so a+ # sustained shortage that outlasts that budget is still transient — the same+ # reaches-here-only-after-internal-retries-exhaust case as the two entries above.+ return {+ "terminating connection due to",+ "the database system is shutting down",+ *_CONNECTION_LIMIT_ERROR_SUBSTRINGS,+ }def reconcile_schema_metadata(self,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 a55cf81da9cd..00a89607fd04 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@@ -1256,6 +1256,30 @@ class TestPostgresSourceRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert not is_non_retryable, f"Server-shutting-down error should not be non-retryable: {error_msg}"+ @pytest.mark.parametrize(+ "error_msg",+ [+ # SQLSTATE 53300: the source (or a pooler in front of it) refuses a new connection+ # because only the superuser-reserved slots remain. `_connect_with_dropped_retry`+ # already retries this in-process on the read/sync connect path; this is the+ # whole-activity-retry fallback for when a sustained shortage outlasts that budget.+ 'connection failed: connection to server at "10.0.0.1", port 5432 failed: '+ "FATAL: remaining connection slots are reserved for roles with the SUPERUSER attribute",+ "sorry, too many clients already",+ "too many connections for role",+ ],+ )+ def test_connection_limit_is_classified_retryable(self, source, error_msg):+ retryable = source.get_retryable_errors()+ is_retryable = any(pattern in error_msg.lower() for pattern in retryable)+ assert is_retryable, f"Connection-limit error should be classified retryable: {error_msg}"++ def test_connection_limit_is_not_also_non_retryable(self, source):+ error_msg = "remaining connection slots are reserved for roles with the SUPERUSER attribute"+ 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"Connection-limit 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