: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(clickhouse): classify self-recovering connect errors as retryable (#72400)
Tom Owers156f3d6afacf
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.pyindex e25ab1011e7c..1373f13a456b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py@@ -257,6 +257,28 @@ class ClickHouseSource(SimpleSource[ClickHouseSourceConfig], SSHTunnelMixin, Val"is not supported for conversion into Arrow data format": "One of the columns in this table has a type ClickHouse can't export (for example an `AggregateFunction` state column on an aggregating materialized view). Deselect that column in this schema's column settings, or sync a view that finalizes it, then resync.",}+ def get_retryable_errors(self) -> set[str]:+ # `_get_client` already retries dropped connections and rate limits in-process+ # (see clickhouse.py's `_is_retryable_connect_error`) before re-raising as+ # `ClickHouseConnectionError`. Bare HTTP 502/503/504 responses skip that+ # in-process retry by design (there's no proxy CONNECT to re-dial) and go+ # straight to Temporal's activity retry instead. Either way, once Temporal+ # retries the activity the failure is transient and self-recovering, so+ # don't surface it as tracked exception noise.+ return {+ "UNEXPECTED_EOF_WHILE_READING",+ "EOF occurred in violation of protocol",+ "Connection reset by peer",+ "Connection aborted",+ "Tunnel connection failed: 502",+ "Tunnel connection failed: 503",+ "Tunnel connection failed: 504",+ "returned response code 429",+ "returned response code 502",+ "returned response code 503",+ "returned response code 504",+ }+def get_schemas(self,config: ClickHouseSourceConfig,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.pyindex 23c466f0c796..5f01888d272c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py@@ -680,6 +680,43 @@ class TestClickHouseSourceNonRetryableErrors:assert not is_non_retryable, f"Transient error should be retryable: {error_msg}"+class TestClickHouseSourceRetryableErrors:+ @pytest.fixture+ def source(self):+ return ClickHouseSource()++ @pytest.mark.parametrize(+ "error_msg",+ [+ # The exact wrapped message that reached error tracking: a bare HTTP 502+ # from clickhouse-connect's HTTPDriver (no proxy CONNECT tunnel involved).+ "HTTPDriver for https://example.ngrok-free.dev:443 returned response code 502",+ "HTTPDriver for https://example.ngrok-free.dev:443 returned response code 503",+ "HTTPDriver for https://example.ngrok-free.dev:443 returned response code 504",+ "HTTPDriver for https://example.ngrok-free.dev:443 returned response code 429",+ "Tunnel connection failed: 502 Bad gateway",+ "Tunnel connection failed: 503 Service Unavailable",+ "Tunnel connection failed: 504 Gateway Timeout",+ "EOF occurred in violation of protocol",+ "Connection reset by peer",+ ],+ )+ def test_transient_errors_are_retryable(self, source, error_msg):+ retryable = source.get_retryable_errors()+ assert any(pattern in error_msg for pattern in retryable), (+ f"Transient, self-recovering error should be classified as retryable (kept out of "+ f"error tracking): {error_msg}"+ )++ def test_permanent_errors_are_not_classified_as_retryable(self, source):+ # A 404 is a deterministic failure (already asserted non-retryable above) — it must not+ # also be misclassified as a benign retryable error, or `_handle_import_error` would log+ # it at `warning` and mask the real cause.+ error_msg = "HTTPDriver for https://example.ngrok-free.dev:443 returned response code 404"+ retryable = source.get_retryable_errors()+ assert not any(pattern in error_msg for pattern in retryable)++class TestIsTransientConnectDrop:@pytest.mark.parametrize("message",