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): treat max_connections_per_hour resource limit as non-retryable (#83028)

Tom Owersb6491307ad66
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 432b74ad548e..585d831ee547 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
@@ -288,6 +288,14 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabase
# egress / SSH-tunnel host) — retrying connects from the same host fails identically.
# Match the stable tail phrase, not the volatile host in the message prefix.
"is not allowed to connect to this MySQL server": "Your MySQL/MariaDB server isn't allowing connections from PostHog's host (error 1130). Ask your database admin to grant access for the connecting host (or allow our IP / SSH-tunnel host), then retry the sync.",
+ # MySQL/MariaDB error 1226 (ER_USER_LIMIT_REACHED): the connecting user account has a
+ # `MAX_CONNECTIONS_PER_HOUR` resource limit set (via `CREATE USER`/`GRANT ... WITH
+ # MAX_CONNECTIONS_PER_HOUR`), and this hour's quota is used up. The counter only resets
+ # at the top of the next clock hour, so retrying immediately keeps failing identically
+ # and just spends more of the next hour's quota re-attempting — only a DB admin raising
+ # or removing the limit fixes it. Match the locale-independent error code (the username
+ # and current-value count are volatile).
+ "(1226,": "Your MySQL/MariaDB user account has a 'max_connections_per_hour' resource limit configured, and PostHog has used it up for this hour (error 1226). The limit resets at the top of the next hour, but retrying now only spends more of that quota. Ask your database admin to raise or remove the limit on the connecting user, then resync.",
# MySQL/MariaDB error 1142 (ER_TABLEACCESS_DENIED_ERROR): the connecting user authenticated
# fine but lacks the SELECT privilege on a table the sync reads — distinct from the 1045
# login failure already handled above. Only a DB admin can GRANT it, and the streaming query
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 8cb32dfe6d47..759738be5283 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
@@ -2070,6 +2070,25 @@ class TestMySQLSourceNonRetryableErrors:
is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
assert is_non_retryable, f"Host-not-privileged error should be non-retryable: {error_msg}"
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ # Raw pymysql str(error) form.
+ str(
+ pymysql.err.OperationalError(
+ 1226,
+ "User 'app_user' has exceeded the 'max_connections_per_hour' resource (current value: 10)",
+ )
+ ),
+ # Temporal-wrapped str(e.cause) form — different user/quota, same stable code.
+ "OperationalError: (1226, \"User 'reader'@'10.0.1.5' has exceeded the 'max_connections_per_hour' resource (current value: 5)\")",
+ ],
+ )
+ def test_max_connections_per_hour_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"Max-connections-per-hour error should be non-retryable: {error_msg}"
+
@pytest.mark.parametrize(
"error_msg",
[