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(mongodb): classify replica-set failover reads as retryable noise (#94574)

Tom Owers8d8634ae6489
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/source.py
index 79ee009fe836..c9499a8cc1ac 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/source.py
@@ -201,7 +201,14 @@ class MongoDBSource(SimpleSource[MongoDBSourceConfig], ValidateDatabaseHostMixin
# from the persistent "Topology Description:" server-selection failures above. Match the
# fixed "connection pool paused" phrase pymongo always uses for this state, not the
# surrounding host/timeout values.
- return {"The resolution lifetime expired", "connection pool paused"}
+ #
+ # pymongo raises NotPrimaryError when an in-flight read is killed because the server node
+ # is shutting down or stepping down (OperationFailure codeName 'InterruptedAtShutdown',
+ # code 11600) — a routine replica-set failover such as a rolling restart or managed-cluster
+ # maintenance. The driver reconnects to the newly-elected primary, so Temporal retrying the
+ # whole activity is self-recovering. Match the stable errmsg phrase, not the volatile
+ # topologyVersion/clusterTime blob pymongo appends.
+ return {"The resolution lifetime expired", "connection pool paused", "interrupted at shutdown"}
def get_schemas(
self,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/test_mongo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/test_mongo.py
index c96dc242fe69..c0d82035975b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/test_mongo.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/test_mongo.py
@@ -515,6 +515,17 @@ class TestGetRetryableErrors(SimpleTestCase):
f"MongoDB connection pool paused should be classified retryable: {error_msg}"
)
+ def test_interrupted_at_shutdown_is_classified_retryable(self):
+ # NotPrimaryError raised when a read is killed by a routine replica-set failover (the
+ # primary shutting down or stepping down); the next retry hits the new primary.
+ error_msg = (
+ "PlanExecutor error during aggregation :: caused by :: interrupted at shutdown, "
+ "full error: {'ok': 0.0, 'code': 11600, 'codeName': 'InterruptedAtShutdown'}"
+ )
+ assert any(pattern in error_msg for pattern in self.retryable), (
+ f"MongoDB shutdown failover should be classified retryable: {error_msg}"
+ )
+
class TestGetRowsToSync(SimpleTestCase):
"""rows_to_sync is a best-effort progress estimate; a failed count must degrade to