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): treat Atlas SQL endpoints as non-retryable (#63761)

Tom Owers04d96818c648
diff --git a/posthog/temporal/data_imports/sources/mongodb/source.py b/posthog/temporal/data_imports/sources/mongodb/source.py
index cf3a02bb1228..eb48ec0baae3 100644
--- a/posthog/temporal/data_imports/sources/mongodb/source.py
+++ b/posthog/temporal/data_imports/sources/mongodb/source.py
@@ -34,6 +34,13 @@ _MONGO_UNREACHABLE_MESSAGE = (
"IP addresses are allowlisted in your database's network access settings."
)
+_MONGO_ATLAS_SQL_MESSAGE = (
+ "This connection string points at a MongoDB Atlas SQL / Data Federation endpoint "
+ "(its host ends in .query.mongodb.net), which PostHog can't import from — those endpoints "
+ "are served by a query proxy for the Atlas SQL ODBC/JDBC drivers, not the standard MongoDB "
+ "driver. Use your regular cluster connection string (e.g. mongodb+srv://...mongodb.net) instead."
+)
+
@SourceRegistry.register
class MongoDBSource(SimpleSource[MongoDBSourceConfig], ValidateDatabaseHostMixin):
@@ -58,6 +65,14 @@ class MongoDBSource(SimpleSource[MongoDBSourceConfig], ValidateDatabaseHostMixin
# case-sensitive), so key off the stable Atlas-specific 'bad auth' prefix.
"bad auth": auth_failed_msg,
"SSL handshake failed": None,
+ # Atlas SQL / Data Federation endpoints live under *.query.mongodb.net and are served by
+ # a query proxy the standard MongoDB driver can't drive: the handshake is closed, the
+ # topology never leaves Unknown, and server selection times out (ServerSelectionTimeoutError,
+ # frequently "connection closed"). This is a wrong-endpoint misconfiguration — the importer
+ # needs a regular cluster connection string — so retrying never recovers. The host suffix
+ # is the stable signal here, and it must be matched before the generic "Topology Description:"
+ # entry below so Atlas SQL users get the wrong-endpoint message rather than the allowlist one.
+ "query.mongodb.net": _MONGO_ATLAS_SQL_MESSAGE,
# pymongo raises ServerSelectionTimeoutError when it can't select a usable cluster node
# for the whole selection timeout. The reason varies — "No servers found yet" / "No
# replica set members found yet" when nothing was ever discovered, or a per-server
diff --git a/posthog/temporal/data_imports/sources/mongodb/test_mongo.py b/posthog/temporal/data_imports/sources/mongodb/test_mongo.py
index 2519a261c8e4..17febd56d75e 100644
--- a/posthog/temporal/data_imports/sources/mongodb/test_mongo.py
+++ b/posthog/temporal/data_imports/sources/mongodb/test_mongo.py
@@ -366,6 +366,18 @@ class TestMongoDBNonRetryableErrors(SimpleTestCase):
"27017: connection closed (configured timeouts: socketTimeoutMS: 20000.0ms, "
"connectTimeoutMS: 20000.0ms)')>]>",
),
+ # Atlas SQL / Data Federation endpoint (*.query.mongodb.net) — unusable by the standard
+ # driver, so the topology stays Unknown and selection times out. Despite the "connection
+ # closed" text, the host suffix marks it as a wrong-endpoint config error, not a blip.
+ (
+ "atlas_sql_endpoint",
+ "atlas-sql-681905984ce3f87167df11fa-wf3cgp.a.query.mongodb.net:27017: connection closed "
+ "(configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms), Timeout: "
+ "10.0s, Topology Description: <TopologyDescription id: 6a304febea674ebc4c8c051e, "
+ "topology_type: Unknown, servers: [<ServerDescription "
+ "('atlas-sql-681905984ce3f87167df11fa-wf3cgp.a.query.mongodb.net', 27017) "
+ "server_type: Unknown, rtt: None, error=AutoReconnect('...connection closed...')>]>",
+ ),
]
)
def test_known_errors_are_non_retryable(self, _name, error_msg):
@@ -398,6 +410,7 @@ class TestMongoDBNonRetryableErrors(SimpleTestCase):
("message", "Authentication failed", "password"),
("atlas_bad_auth", "bad auth", "password"),
("unreachable_topology", "Topology Description:", "allowlist"),
+ ("atlas_sql_endpoint", "query.mongodb.net", "connection string"),
]
)
def test_pattern_has_friendly_message(self, _name, pattern, expected_substring):