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 tracking self-recovering lost-connection errors (#73127)

Tom Owers7ef11ebd6078
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 c8a091957671..bcd637e69e71 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
@@ -281,6 +281,14 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabase
"ordinal not in range(256)": "One of your connection details contains an invisible or unsupported character (for example a zero-width space pasted in from another app). Retype the affected field — host, database, user, or password — by hand instead of pasting it, then re-enable the sync.",
}
+ def get_retryable_errors(self) -> set[str]:
+ # `_connect_with_transient_retry` already retries this exact drop in-process (see
+ # `_is_transient_connect_drop` in mysql.py) before re-raising once its attempt budget is
+ # exhausted; the streaming path's FORCE INDEX fallback does the same for a mid-query drop
+ # (see `_is_bad_plan_error`). Either way, Temporal retries the whole activity next and the
+ # failure is transient and self-recovering, so don't surface it as tracked exception noise.
+ return {"Lost connection to MySQL server during query"}
+
def reconcile_schema_metadata(
self,
source: "ExternalDataSource",
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 143b6b28d396..2114c0b0fd95 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
@@ -1919,6 +1919,22 @@ class TestMySQLSourceNonRetryableErrors:
is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
assert not is_non_retryable, f"Transient lost-connection error should remain retryable: {error_msg}"
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ "OperationalError: (2013, 'Lost connection to MySQL server during query')",
+ "Lost connection to MySQL server during query",
+ ],
+ )
+ def test_transient_lost_connection_is_classified_retryable(self, source, error_msg):
+ # Already retried in-process (connect-time and streaming-query FORCE INDEX fallback); once
+ # exhausted it re-raises for Temporal to retry the whole activity. Without this
+ # classification `_handle_import_error` logs it at `exception` on every occurrence,
+ # flooding error tracking with a self-recovering failure.
+ retryable = source.get_retryable_errors()
+ is_retryable = any(pattern in error_msg for pattern in retryable)
+ assert is_retryable, f"Transient lost-connection error should be classified retryable: {error_msg}"
+
@pytest.mark.parametrize(
"error_msg",
[