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(mysql): stop retrying a MySQL server out-of-memory error (#83718)

Tom Owersabe8330c6ae7
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.py
index 585d831ee547..a499b2718796 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
@@ -341,6 +341,13 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabase
# customer's server running out of space.
"OS errno 28 -": "Your MySQL/MariaDB server ran out of disk space while writing a temporary file for this sync ('No space left on device'). Syncing a large table can spill a big sort to the server's temporary directory. Free up disk space on your database server, add an index on this table's incremental field so the sync avoids the large sort, or switch the table to a full re-sync, then resync.",
"Errcode: 28": "Your MySQL/MariaDB server ran out of disk space while writing a temporary file for this sync ('No space left on device'). Syncing a large table can spill a big sort to the server's temporary directory. Free up disk space on your database server, add an index on this table's incremental field so the sync avoids the large sort, or switch the table to a full re-sync, then resync.",
+ # MySQL/MariaDB error 1041 (ER_OUT_OF_RESOURCES): mysqld itself couldn't allocate memory
+ # for the connection/query — the host's available memory (or its configured swap) is
+ # exhausted, whether by mysqld or another process on the same host. Static server-side
+ # resource state, so every retry hits the same wall — the Postgres source treats its
+ # equivalent (SQLSTATE 53200 "out of memory") the same way. Match the locale-independent
+ # error code (the trailing "ulimit"/swap guidance is MySQL's own, not translated).
+ "(1041,": "Your MySQL/MariaDB server ran out of memory (error 1041). This usually means mysqld or another process on the host is using all available memory, or the host needs more swap space. Free up memory on your database server, raise mysqld's memory limit (for example via 'ulimit'), or add swap space, then resync.",
# pymysql encodes the handshake fields (host, user, password, database) as latin-1;
# a value carrying a non-latin-1 character — most often an invisible zero-width space
# (U+200B) pasted in from another app — raises UnicodeEncodeError before any packet is
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.py
index 759738be5283..bd97f2046692 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
@@ -2140,6 +2140,28 @@ class TestMySQLSourceNonRetryableErrors:
is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
assert is_non_retryable, f"Query-execution-time-exceeded 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(
+ 1041,
+ "Out of memory; check if mysqld or some other process uses all available memory; if not, "
+ "you may have to use 'ulimit' to allow mysqld to use more memory or you can add more swap space",
+ )
+ ),
+ # Temporal-wrapped form (double-quoted).
+ 'OperationalError: (1041, "Out of memory; check if mysqld or some other process uses all available '
+ "memory; if not, you may have to use 'ulimit' to allow mysqld to use more memory or you can add more "
+ 'swap space")',
+ ],
+ )
+ def test_out_of_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-memory error should be non-retryable: {error_msg}"
+
@pytest.mark.parametrize(
"error_msg",
[