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): stop reporting execution-timeout getMore as an error (#104628)

Tom Owersa699cd7fed58
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 ac4a0a9540ca..1e7badd16ac4 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
@@ -270,6 +270,14 @@ class MongoDBSource(SimpleSource[MongoDBSourceConfig], ValidateDatabaseHostMixin
# pymongo wraps a bare ConnectionResetError in AutoReconnect the same way, when a socket a
# cursor is reading from gets an RST mid-sync (a load balancer or the server ending an idle
# connection) rather than timing out. Same recovery path as the timeout case above.
+ #
+ # OperationFailure code 50 (MaxTimeMSExpired / pymongo's ExecutionTimeout) fires when a
+ # getMore is killed by a cluster-enforced execution-time cap we never configure ourselves
+ # (mongo.py's _EXECUTION_TIMEOUT_ERROR_CODE) — notably Atlas free/shared/flex tiers. mongo.py
+ # already resumes from last_id when this happens mid-stream, and only re-raises when a
+ # getMore was killed before yielding anything (resuming immediately would hit the same cap
+ # in a tight loop). A fresh Temporal retry isn't bound by that same in-flight time budget, so
+ # it is self-recovering and must not flood error tracking on every no-progress getMore.
return {
"The resolution lifetime expired",
"connection pool paused",
@@ -278,6 +286,7 @@ class MongoDBSource(SimpleSource[MongoDBSourceConfig], ValidateDatabaseHostMixin
"Topology Description:",
"timed out (configured timeouts:",
"Connection reset by peer",
+ "operation exceeded time limit",
}
def get_retry_exhausted_errors(self) -> dict[str, str]:
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 a047a3c0aa88..909bbc4038db 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
@@ -645,6 +645,22 @@ class TestGetRetryableErrors(SimpleTestCase):
f"MongoDB shutdown failover should be classified retryable: {error_msg}"
)
+ def test_execution_timeout_is_classified_retryable(self):
+ # mongo.py re-raises OperationFailure code 50 (MaxTimeMSExpired) unchanged when a getMore
+ # is killed before yielding anything (see TestMongoSourceCursorLifecycle's
+ # test_execution_timeout_without_progress_is_not_retried_forever). A fresh Temporal retry
+ # isn't bound by the same in-flight execution-time cap, so this must not flood error
+ # tracking on every occurrence.
+ error_msg = (
+ "operation exceeded time limit, correlationID = 18d582877a9d2284f38efbb3 "
+ "(configured timeouts: connectTimeoutMS: 20000.0ms), full error: {'ok': 0, 'errmsg': "
+ "'operation exceeded time limit, correlationID = 18d582877a9d2284f38efbb3', "
+ "'code': 50, 'codeName': 'MaxTimeMSExpired'}"
+ )
+ assert any(pattern in error_msg for pattern in self.retryable), (
+ f"MongoDB execution timeout with no progress should be classified retryable: {error_msg}"
+ )
+
class TestGetRowsToSync(SimpleTestCase):
"""rows_to_sync is a best-effort progress estimate; a failed count must degrade to