: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(mssql): classify a mid-stream deadlock victim as retryable (#129420)
Tom Owers69f817b963db
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.pyindex b54846b9ea49..3fd5872b510e 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@@ -29,6 +29,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.sqlfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceInputs, SourceResponsefrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.mssql import MSSQLSourceConfigfrom products.warehouse_sources.backend.temporal.data_imports.sources.mssql.mssql import (+ _DEADLOCK_VICTIM_ERROR,_SSH_HANDSHAKE_EOF_ERROR,_TABLE_NOT_FOUND_ERROR,MSSQL_METADATA_TIMEOUT_ERROR,@@ -164,6 +165,13 @@ class MSSQLSource(# checkpoint where the read has one, can succeed.MSSQL_ROW_READ_TIMEOUT_ERROR,_TEMPDB_ALLOCATION_FAILED_ERROR,+ # SQL Server error 1205. `retry_on_deadlock` already reruns the dispatching query+ # in-process, but a deadlock chosen mid-stream — while `cursor.fetchmany` is pulling+ # later batches of an already-executing read — can't be retried the same way: the+ # cursor's result set is gone, and re-running the query would re-yield rows already+ # handed to the pipeline. That case surfaces here instead, and a fresh attempt from+ # the next Temporal retry (or checkpoint, where the read supports one) recovers it.+ _DEADLOCK_VICTIM_ERROR,}def get_retry_exhausted_errors(self) -> dict[str, str]: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.pyindex 6d8ce491ba67..133f2bf25e60 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,13 @@ 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"),+ # 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(+ 1205,+ b"Transaction (Process ID 116) was deadlocked on lock resources with another process and has been "+ b"chosen as the deadlock victim. Rerun the transaction.",+ ),],)def test_transient_connection_errors_are_retryable(self, error):