: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): stop retrying an SSH tunnel host that fails safety checks (#77012)
Tom Owers2251711fd38f
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 006a80f02701..f2f9753c8e5f 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@@ -230,6 +230,18 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabase# retries forever. `connect` re-raises it as `_SSH_HANDSHAKE_EOF_ERROR` — same# gateway-configuration class as "Could not establish session to SSH gateway" above._SSH_HANDSHAKE_EOF_ERROR: "Could not connect to your SSH tunnel — the gateway accepted the connection but closed it during the SSH handshake. Check that the SSH host and port point to an SSH server (not the database port), that the bastion is running and reachable, and that PostHog's IP addresses are allowed through its firewall, then re-enable the sync.",+ # `_pinned_ssh_host` (common/mixins.py) re-checks the SSH tunnel host on every connect,+ # since a host that resolved to a public address at setup can drift (DNS change, or a+ # short-TTL record). It rejects the host if it doesn't resolve or resolves to a+ # private/internal address, which is a config problem only the customer can fix, so+ # retrying just re-hits the same rejection. Match the stable prefix and exclude the+ # volatile host/IP details that follow it in `resolution.error`.+ "SSH tunnel host not allowed": (+ "PostHog rejected the SSH tunnel host for this source because it either couldn't "+ "be resolved, or resolves to a private/internal address. Check that the SSH tunnel "+ "host is spelled correctly and reachable from the public internet, then re-enable "+ "the sync."+ ),# MySQL/MariaDB error 1129 (ER_HOST_IS_BLOCKED): the server has blocked our import# host because aborted/interrupted connections from it exceeded `max_connect_errors`.# The block is server-side state that only a DB admin can clear (FLUSH HOSTS /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 404fa0704c1e..46842345f120 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@@ -1865,6 +1865,27 @@ class TestMySQLSourceNonRetryableErrors:is_non_retryable = any(pattern in _SSH_HANDSHAKE_EOF_ERROR for pattern in non_retryable.keys())assert is_non_retryable, f"SSH handshake EOF should be non-retryable: {_SSH_HANDSHAKE_EOF_ERROR}"+ @pytest.mark.parametrize(+ "error_msg",+ [+ # DNS resolution failure for the configured SSH tunnel host (`_pinned_ssh_host` in+ # common/mixins.py).+ "SSH tunnel host not allowed: Couldn't resolve the host 'bastion.example.com'. Check "+ "that it's spelled correctly and reachable from the public internet.",+ # Temporal-wrapped form carrying the exception class name.+ "Exception: SSH tunnel host not allowed: Couldn't resolve the host 'bastion.example.com'. "+ "Check that it's spelled correctly and reachable from the public internet.",+ # The other rejection `_pinned_ssh_host` can raise: the host resolves to a private/internal address.+ "SSH tunnel host not allowed: This host points to an internal or private IP address, "+ "which PostHog can't reach. Use a host that's reachable from the public internet.",+ ],+ )+ def test_ssh_tunnel_host_not_allowed_is_non_retryable(self, source, error_msg):+ non_retryable = source.get_non_retryable_errors()+ assert "SSH tunnel host not allowed" in non_retryable+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())+ assert is_non_retryable, f"SSH tunnel host rejection should be non-retryable: {error_msg}"+@pytest.mark.parametrize("error_msg",[