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(mssql): name likely causes when the server drops the connection at setup (#125305)

Tom Owersbd175864b04d
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/source.py
index d806b24ea2de..b54846b9ea49 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/source.py
@@ -64,6 +64,13 @@ _CONNECTION_TIMED_OUT_ERROR = (
_GENERIC_CONNECTION_ERROR = "Could not connect to MS SQL. Please check all connection details are valid."
+# DB-Lib error 20002 at setup, usually paired with 20017 ("Unexpected EOF from the server"): the server
+# dropped the connection mid-handshake. Mirrors the Postgres source's wording for the same failure.
+_CONNECTION_DROPPED_ERROR = (
+ "Your SQL Server closed the connection while PostHog was connecting. Check your host, port, and "
+ "encryption settings, and that no firewall or SSH tunnel is dropping the connection."
+)
+
# SQL Server error 1105 in tempdb. tempdb is shared across sessions, so a concurrent workload that
# filled it can release it; scoped to tempdb so a customer database genuinely out of disk isn't matched.
_TEMPDB_ALLOCATION_FAILED_ERROR = "in database 'tempdb' because the '"
@@ -86,9 +93,8 @@ MSSQLErrors = {
"connection timed out": _CONNECTION_TIMED_OUT_ERROR,
# DB-Lib error 20002, the generic connect-time failure `get_non_retryable_errors` below also
# matches (and leaves unmapped there since the cause varies). Map it here too so a credential
- # check that hits it returns the same generic guidance as an unmatched error already gets,
- # instead of falling through to `capture_exception` as a bug.
- "Adaptive Server connection failed": _GENERIC_CONNECTION_ERROR,
+ # check that hits it names the likely causes instead of falling through to `capture_exception`.
+ "Adaptive Server connection failed": _CONNECTION_DROPPED_ERROR,
}
_MSSQL_IMPLEMENTATION = MSSQLImplementation()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/tests/test_mssql.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/tests/test_mssql.py
index ab6c3d979d60..44879a570177 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/tests/test_mssql.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/tests/test_mssql.py
@@ -33,8 +33,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.mssql.mssq
retry_on_transient_connection_error,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.mssql.source import (
+ _CONNECTION_DROPPED_ERROR,
_FIREWALL_BLOCKED_ERROR,
- _GENERIC_CONNECTION_ERROR,
MSSQLSource,
)
from products.warehouse_sources.backend.types import IncrementalFieldType
@@ -719,7 +719,7 @@ class TestMSSQLSourceValidateCredentials:
assert error == _FIREWALL_BLOCKED_ERROR
capture.assert_not_called()
- def test_adaptive_server_connection_failed_returns_generic_message_without_capturing(self, source, mocker):
+ def test_adaptive_server_connection_failed_names_likely_causes_without_capturing(self, source, mocker):
capture = mocker.patch(
"products.warehouse_sources.backend.temporal.data_imports.sources.mssql.source.capture_exception"
)
@@ -736,7 +736,7 @@ class TestMSSQLSourceValidateCredentials:
valid, error = source.validate_credentials(_make_config(), team_id=1)
assert valid is False
- assert error == _GENERIC_CONNECTION_ERROR
+ assert error == _CONNECTION_DROPPED_ERROR
capture.assert_not_called()
@pytest.mark.parametrize(