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(data-imports): suppress AdminShutdown capture in best-effort shutdown lease release (#91342)

Tom Owersd3782aecb901
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.py
index 9b52e71eab2e..2d654ed9fb44 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.py
@@ -1390,8 +1390,12 @@ class BatchConsumer:
try:
await self._adapter.release_all_owned(self._poll_conn, owner_token=self._owner_token)
except Exception as e:
- logger.exception(self._event("release_all_owned_failed_on_shutdown"))
- capture_exception(e)
+ if _is_admin_shutdown_error(e):
+ # Admin-initiated disconnect during teardown is expected; the lease just expires.
+ logger.warning(self._event("release_all_owned_admin_shutdown"), error=str(e))
+ else:
+ logger.exception(self._event("release_all_owned_failed_on_shutdown"))
+ capture_exception(e)
if self._poll_conn is not None and not self._poll_conn.closed:
await self._poll_conn.close()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py
index f210930944ba..aedb1efb1f51 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py
@@ -892,6 +892,26 @@ class TestAdminShutdownErrorClassification:
mock_capture.assert_not_called()
+ @pytest.mark.asyncio
+ async def test_close_does_not_report_admin_shutdown_error(self):
+ # Queue DB terminates the poll connection via an administrator command (failover,
+ # maintenance restart) while _close() tries the best-effort lease release.
+ # _close() already notes this path is best-effort; the error must not reach
+ # error tracking.
+ consumer = _make_consumer()
+ with (
+ patch.object(
+ consumer._adapter,
+ "release_all_owned",
+ new_callable=AsyncMock,
+ side_effect=psycopg.errors.AdminShutdown("terminating connection due to administrator command"),
+ ),
+ patch(f"{batch_consumer_module.__name__}.capture_exception") as mock_capture,
+ ):
+ await consumer._close()
+
+ mock_capture.assert_not_called()
+
class TestStartupLiveness:
@pytest.mark.asyncio