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): classify dead connections as retryable during row reads (#130642)

Tom Owers6411e7fe2056
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 3fd5872b510e..25a2a657463d 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
@@ -32,6 +32,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.mssql.mssq
_DEADLOCK_VICTIM_ERROR,
_SSH_HANDSHAKE_EOF_ERROR,
_TABLE_NOT_FOUND_ERROR,
+ _TRANSIENT_CONNECTION_ERROR,
MSSQL_METADATA_TIMEOUT_ERROR,
MSSQL_ROW_READ_TIMEOUT_ERROR,
MSSQL_SCHEMA_DISCOVERY_DEADLINE_SECONDS,
@@ -155,6 +156,12 @@ class MSSQLSource(
# died between opening and the query running — just surfaced through a different
# internal code path. A fresh connection from the next Temporal retry resolves it.
"Not connected to any MS SQL server",
+ # DB-Lib error 20047, the same DBPROCESS-death class raised directly (see
+ # `_is_transient_connection_error` in mssql.py): the TDS connection died mid-stream
+ # during the row read itself, past the point `retry_on_transient_connection_error`
+ # covers (that helper only wraps schema discovery). A fresh connection from the next
+ # Temporal retry resolves it.
+ _TRANSIENT_CONNECTION_ERROR,
# SQL Server error 1222. A metadata statement waited longer than the `SET LOCK_TIMEOUT`
# that `MSSQLImplementation.connect` sets, because another session held a lock on the
# catalog or on the table. The lock belongs to the customer's own workload and goes
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 133f2bf25e60..1d8bcbd74083 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
@@ -686,6 +686,12 @@ class TestMSSQLSourceRetryableErrors:
# pymssql's own InterfaceError, raised when a query runs on a connection that died
# between opening and use (see `MSSQLSource.get_retryable_errors`).
pymssql.InterfaceError("Not connected to any MS SQL server"),
+ # DB-Lib error 20047 raised directly from `cursor.fetchmany` during the row read
+ # (see `MSSQLSource.get_retryable_errors`) — the same DBPROCESS-death class as the
+ # 20017 case above, past the point `retry_on_transient_connection_error` covers.
+ pymssql.OperationalError(
+ 20047, b"DB-Lib error message 20047, severity 9:\nDBPROCESS is dead or not enabled\n"
+ ),
# SQL Server error 1205 raised mid-stream from `cursor.fetchmany`, past the point
# `retry_on_deadlock` can safely rerun the query (see `MSSQLSource.get_retryable_errors`).
pymssql.OperationalError(