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 mid-sync connection reset as retryable (#103804)

Tom Owersde97176d16c2
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 840160396537..ac4a0a9540ca 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
@@ -266,6 +266,10 @@ class MongoDBSource(SimpleSource[MongoDBSourceConfig], ValidateDatabaseHostMixin
# 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.
+ #
+ # 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.
return {
"The resolution lifetime expired",
"connection pool paused",
@@ -273,6 +277,7 @@ class MongoDBSource(SimpleSource[MongoDBSourceConfig], ValidateDatabaseHostMixin
"interrupted at shutdown",
"Topology Description:",
"timed out (configured timeouts:",
+ "Connection reset by peer",
}
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 0b0a686b04f9..a047a3c0aa88 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
@@ -622,6 +622,18 @@ class TestGetRetryableErrors(SimpleTestCase):
assert "Topology Description" not in message
assert expected_phrase in message.lower()
+ def test_connection_reset_is_classified_retryable(self):
+ # AutoReconnect wrapping a bare ConnectionResetError mid-cursor-read (an RST, not a
+ # timeout) — the next connection attempt succeeds once the network recovers, so this must
+ # not flood error tracking as an unclassified exception on every retry.
+ error_msg = (
+ "cluster0.example.mongodb.net:27017: [Errno 104] Connection reset by peer "
+ "(configured timeouts: connectTimeoutMS: 20000.0ms)"
+ )
+ assert any(pattern in error_msg for pattern in self.retryable), (
+ f"MongoDB connection reset 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.