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): stop flooding error tracking on RLS check recovery conflicts (#125285)

Tom Owers0c21f5b9cfbd
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.py
index a3876ef32f4b..7f278b301e83 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
@@ -1587,6 +1587,9 @@ def _rls_active_from_conn(
# Temporal cancelling the activity mid-probe (user cancelled the sync, or the activity hit
# its `start_to_close_timeout`) is the same shape too: the sync is ending regardless of
# what this best-effort lookup returns, so there's nothing to fix here.
+ # A hot-standby recovery conflict (`_is_recovery_conflict_error`) cancelling this catalog
+ # query is the same transient condition `get_rows` already retries on the main read path —
+ # this lookup just has no retry loop of its own, so degrade quietly instead of capturing it.
# Still capture genuinely unexpected failures.
if (
not connection.closed
@@ -1597,6 +1600,7 @@ def _rls_active_from_conn(
and not _is_statement_timeout_error(e)
and not _is_pooler_login_cooldown_error(e)
and not _is_activity_cancelled(e)
+ and not _is_recovery_conflict_error(e)
):
capture_exception(e)
return {}
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.py
index 5f76142a30b3..d8d95b225823 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
@@ -10411,6 +10411,21 @@ class TestRlsActiveFromConnErrorHandling:
assert result == {}
capture_mock.assert_called_once()
+ def test_recovery_conflict_error_is_not_captured(self):
+ # A hot-standby recovery conflict cancelling this catalog query is the same transient
+ # condition the main read path already retries (`get_rows` via `_is_recovery_conflict_error`).
+ # This best-effort lookup has no retry loop of its own: degrade quietly rather than flooding
+ # error tracking with a condition that isn't a bug.
+ conn = self._conn_raising(
+ psycopg.errors.SerializationFailure("canceling statement due to conflict with recovery")
+ )
+ with patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.postgres.postgres.capture_exception"
+ ) as capture_mock:
+ result = _rls_active_from_conn(cast(Any, conn), "public", ["t"])
+ assert result == {}
+ capture_mock.assert_not_called()
+
def test_pooler_login_cooldown_error_is_not_captured(self):
# A Postgres-wire-compatible source backed by DuckDB's `postgres_query()` (e.g. DuckLake's
# duckgres bridge) can surface a transient PgBouncer server_login_retry cooldown wrapped in