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 a connect-timeout NetworkTimeout as retryable (#102706)

Tom Owersaec0f961518c
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 e8ad01c88be0..c5701ada11a0 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
@@ -248,12 +248,20 @@ class MongoDBSource(SimpleSource[MongoDBSourceConfig], ValidateDatabaseHostMixin
# 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.
+ #
+ # pymongo raises NetworkTimeout (a socket.timeout wrapped by _raise_connection_failure) when
+ # opening a fresh connection — to replace one the pool dropped, mid-sync — takes longer than
+ # connectTimeoutMS. This is the same class of momentary network blip as "connection pool
+ # paused" above, not a persistently unreachable cluster: it carries a host and configured
+ # timeouts but no "Topology Description:" dump, and the next connection attempt (this one,
+ # or a fresh one on the activity's Temporal retry) succeeds once the network recovers.
return {
"The resolution lifetime expired",
"connection pool paused",
"the cluster's signing keys were briefly unavailable",
"interrupted at shutdown",
"Topology Description:",
+ "timed out (configured timeouts:",
}
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 1dc5a0a23230..b0157fbeb90a 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
@@ -556,6 +556,15 @@ class TestGetRetryableErrors(SimpleTestCase):
f"MongoDB connection pool paused should be classified retryable: {error_msg}"
)
+ def test_network_timeout_is_classified_retryable(self):
+ # NetworkTimeout raised when opening a fresh connection (replacing one the pool dropped)
+ # takes longer than connectTimeoutMS — a momentary network blip, not a persistently
+ # unreachable cluster, so it must not flood error tracking on every occurrence.
+ error_msg = "cluster0.example.mongodb.net:27017: timed out (configured timeouts: connectTimeoutMS: 20000.0ms)"
+ assert any(pattern in error_msg for pattern in self.retryable), (
+ f"MongoDB NetworkTimeout on connect should be classified retryable: {error_msg}"
+ )
+
def test_signing_keys_unavailable_is_classified_retryable(self):
# mongo.py rewrites OperationFailure code 211 (KeyNotFound) to this message, so it is the
# text that reaches classification. Without a match the run reports as a bug nobody can act