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): skip tracking tempdb-log-full errors in table stats (#125246)

Tom Owersa9a6d8f19d99
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.py
index d11b9d96198a..5cf7b599c493 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.py
@@ -171,6 +171,20 @@ def run_metadata_with_deadline(operation: Callable[[], _T], *, action: str, time
_TRANSIENT_CONNECTION_ERROR = "DBPROCESS is dead or not enabled"
_MAX_DISCOVERY_CONNECTION_ATTEMPTS = 5
+# SQL Server error 9002 raised while running `sp_spaceused` for table stats. The transaction log
+# for the shared `tempdb` database filled up because another session's active transaction is
+# holding it open, so it can't be truncated — this clears once that transaction ends or is rolled
+# back and a later attempt can succeed. `fetch_table_stats` is best-effort, so this is matched like
+# `_is_transient_connection_error` below and skipped rather than captured as tracked noise.
+_TEMPDB_LOG_FULL_ERROR = "The transaction log for database 'tempdb' is full"
+
+
+def _is_tempdb_log_full_error(error: BaseException) -> bool:
+ """True for a SQL Server 9002 tempdb-log-full error that clears once the holding transaction ends."""
+ message = " ".join(str(arg) for arg in error.args) if error.args else str(error)
+ return _TEMPDB_LOG_FULL_ERROR in message
+
+
# SQL Server error 1205 — this session was picked as the deadlock victim and its transaction was
# rolled back to break a lock cycle with a concurrent process. SQL Server's own guidance is to
# rerun the transaction: lock contention is momentary, so re-running the identical query usually
@@ -1136,10 +1150,11 @@ class MSSQLImplementation(SQLSourceImplementation[MSSQLSourceConfig, pymssql.Con
return TableStats(table_size_bytes=total_bytes, row_count=total_rows)
except Exception as e:
# A transient connection death recovers on the next sync attempt with a fresh
- # connection (see `retry_on_transient_connection_error`); table stats are best-effort,
- # so skip capturing this known, self-recovering error as tracked noise.
- if isinstance(e, pymssql.Error) and _is_transient_connection_error(e):
- logger.debug(f"fetch_table_stats: transient MSSQL connection death, returning None: {e}")
+ # connection (see `retry_on_transient_connection_error`); a tempdb-log-full error
+ # recovers once the other session's transaction ends; table stats are best-effort, so
+ # both are skipped rather than captured as tracked noise.
+ if isinstance(e, pymssql.Error) and (_is_transient_connection_error(e) or _is_tempdb_log_full_error(e)):
+ logger.debug(f"fetch_table_stats: known self-recovering MSSQL error, returning None: {e}")
return None
logger.debug(f"fetch_table_stats: Error: {e}. Returning None", exc_info=e)
capture_exception(e)
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 2d7bd692dfe6..6d8ce491ba67 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
@@ -322,6 +322,21 @@ class TestFetchTableStats:
assert cursor.execute.call_count == 1
capture.assert_not_called()
+ def test_tempdb_log_full_skips_capture(self, impl, cursor, logger, mocker):
+ # SQL Server 9002: another session's active transaction filled tempdb's log. This clears
+ # once that transaction ends, so it's as self-recovering as the connection-death case above
+ # and must not flood error tracking.
+ capture = mocker.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.mssql.mssql.capture_exception"
+ )
+ cursor.execute.side_effect = pymssql.OperationalError(
+ 9002,
+ b"The transaction log for database 'tempdb' is full due to 'ACTIVE_TRANSACTION' and the holdup lsn "
+ b"is (1:2:3).DB-Lib error message 20018, severity 17:\nGeneral SQL Server error\n",
+ )
+ assert impl.fetch_table_stats(cursor, "dbo", "t", logger) is None
+ capture.assert_not_called()
+
class TestFetchAverageRowSize:
"""MSSQL's `fetch_average_row_size` samples a separate `TOP 100` query