: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(mysql): treat out-of-sort-memory (1038) as non-retryable (#64633)
Tom Owers110c6c81daf9
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/source.pyindex df62fe4f592d..64210a314c68 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/source.py@@ -250,6 +250,15 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabase# locale-independent error code (the user, host, and table are volatile and the message text# is translated on non-English servers), consistent with the other code-prefixed entries."(1142,": "PostHog's database user doesn't have SELECT permission on a table this sync reads (MySQL error 1142). Ask your database admin to grant SELECT on it, or remove that table from the sync, then resync.",+ # MySQL/MariaDB error 1038 (ER_OUT_OF_SORTMEMORY): the server's `sort_buffer_size` is too+ # small to filesort the `ORDER BY <incremental_field>` the incremental query requires. We+ # already try to dodge the sort with the in-activity FORCE INDEX fallback (see+ # `_is_bad_plan_error`); this only escapes once that fallback can't apply — no usable index+ # on the incremental field. Both `sort_buffer_size` and the missing index are static+ # server-side state, so every retry filesorts the same rows and fails identically. Match the+ # locale-independent error code (the trailing message text is translated on non-English+ # servers) so it catches both the raw pymysql string and the wrapped `(1038, ...)` form.+ "(1038,": "Your MySQL/MariaDB server ran out of sort buffer memory while ordering this table by its incremental field (error 1038). We try to avoid the sort by forcing the incremental field's index, but this table has no usable index on that field. Add an index on the incremental field, raise the server's 'sort_buffer_size', or switch this table to a full re-sync, then resync.",}def reconcile_schema_metadata(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.pyindex d17eed6e3afe..09a407f73e4e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.py@@ -1514,6 +1514,20 @@ class TestMySQLSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable, f"Table-access-denied error should be non-retryable: {error_msg}"+ @pytest.mark.parametrize(+ "error_msg",+ [+ # Raw pymysql str(error) form (single-quoted tuple repr).+ str(pymysql.err.OperationalError(1038, "Out of sort memory, consider increasing server sort buffer size")),+ # Temporal-wrapped form (double-quoted).+ 'OperationalError: (1038, "Out of sort memory, consider increasing server sort buffer size")',+ ],+ )+ def test_out_of_sort_memory_is_non_retryable(self, source, error_msg):+ non_retryable = source.get_non_retryable_errors()+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())+ assert is_non_retryable, f"Out-of-sort-memory error should be non-retryable: {error_msg}"+@pytest.mark.parametrize("error_msg",[