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(data-warehouse): mark MSSQL unreachable-server errors as non-retryable (#61640)

Tom Owers94d3d1fd62b4
diff --git a/posthog/temporal/data_imports/sources/mssql/source.py b/posthog/temporal/data_imports/sources/mssql/source.py
index f412af471c0f..66c9a83204c9 100644
--- a/posthog/temporal/data_imports/sources/mssql/source.py
+++ b/posthog/temporal/data_imports/sources/mssql/source.py
@@ -42,6 +42,11 @@ class MSSQLSource(SQLSource[MSSQLSourceConfig], SSHTunnelMixin, ValidateDatabase
def get_non_retryable_errors(self) -> dict[str, str | None]:
return {
"Adaptive Server connection failed": None,
+ # pymssql DB-Lib error 20009 — the server host can't be reached for the whole
+ # connection attempt. On a managed instance this is a persistent connectivity issue
+ # (security group doesn't allow PostHog's IPs, the instance is stopped, or the
+ # hostname is wrong), not a momentary blip, so retrying the job won't recover it.
+ "Adaptive Server is unavailable or does not exist": "Could not reach your SQL Server. Check that the server is running and reachable, and that PostHog's IP addresses are allowed through its firewall / security group.",
"Login failed for user": None,
"Cannot find the CREDENTIAL": "Cannot find the credential - check that it exists and you have permission to access it",
# Raised from the shared `_decimal_array_from_values` fallback in
diff --git a/posthog/temporal/data_imports/sources/mssql/tests/test_mssql.py b/posthog/temporal/data_imports/sources/mssql/tests/test_mssql.py
index 745539b206f9..4d1133f1f7cc 100644
--- a/posthog/temporal/data_imports/sources/mssql/tests/test_mssql.py
+++ b/posthog/temporal/data_imports/sources/mssql/tests/test_mssql.py
@@ -432,3 +432,16 @@ class TestMSSQLSourceNonRetryableErrors:
def test_data_shape_errors_are_non_retryable(self, error_msg):
non_retryable = MSSQLSource().get_non_retryable_errors()
assert any(pattern in error_msg for pattern in non_retryable.keys()), error_msg
+
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ # Real pymssql DB-Lib error 20009 for an unreachable host.
+ "DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is "
+ "unavailable or does not exist (cplapps.example.us-east-2.rds.amazonaws.com)",
+ "Login failed for user 'reporting'.",
+ ],
+ )
+ def test_connection_errors_are_non_retryable(self, error_msg):
+ non_retryable = MSSQLSource().get_non_retryable_errors()
+ assert any(pattern in error_msg for pattern in non_retryable.keys()), error_msg