: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): stop reporting a transient http 500 as an error (#115020)
Tom Owers6c3fb07849a7
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/clickhouse.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/clickhouse.pyindex b68e35d86e98..0e2354768743 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/clickhouse.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/clickhouse.py@@ -1195,8 +1195,14 @@ def _get_incremental_row_count(# serve us right now, not that anything we sent was wrong — they clear on their# own. A real ClickHouse query error carries a `Code: NNN` instead. We match# only these transient statuses so genuine failures still surface.+# 500 is included: clickhouse-connect only wraps a response this way (rather than+# "Received ClickHouse exception, code: N") when it carries no+# `X-ClickHouse-Exception-Code` header, which a genuine ClickHouse-raised error+# always sets — so a bare 500 means a proxy/load balancer in front of ClickHouse+# failed, the same shape as 502/503/504._TRANSIENT_HTTP_RESPONSE_SUBSTRINGS: tuple[str, ...] = ("received HTTP status 429",+ "received HTTP status 500","received HTTP status 502","received HTTP status 503","received HTTP status 504",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 54dd4c5c945d..9929b11f53a2 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@@ -133,6 +133,10 @@ ClickHouseErrors: dict[str, str] = {"received http status 307": _REDIRECTED,"received http status 308": _REDIRECTED,"received http status 429": _TEMPORARILY_UNAVAILABLE,+ # A bare 500 (no X-ClickHouse-Exception-Code header, see get_retryable_errors) is a+ # proxy/load balancer in front of ClickHouse failing, not ClickHouse itself — same+ # transient shape as 502/503/504 below.+ "received http status 500": _TEMPORARILY_UNAVAILABLE,"received http status 502": _TEMPORARILY_UNAVAILABLE,"received http status 503": _TEMPORARILY_UNAVAILABLE,"received http status 504": _TEMPORARILY_UNAVAILABLE,@@ -376,7 +380,7 @@ class ClickHouseSource(SimpleSource[ClickHouseSourceConfig], SSHTunnelMixin, Valdef 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+ # `ClickHouseConnectionError`. Bare HTTP 500/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@@ -387,6 +391,11 @@ class ClickHouseSource(SimpleSource[ClickHouseSourceConfig], SSHTunnelMixin, Val"Connection reset by peer","Connection aborted","received HTTP status 429",+ # No X-ClickHouse-Exception-Code header means ClickHouse itself never raised+ # this — a proxy/load balancer in front of it failed instead (see+ # clickhouse.py's NOT_A_CLICKHOUSE_HTTP_RESPONSE and the 400/404 entries+ # above for the same reasoning applied to deterministic bare statuses).+ "received HTTP status 500","received HTTP status 502","received HTTP status 503","received HTTP status 504",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 0d2e88294234..7c711ebc11ac 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@@ -40,6 +40,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.clickhouse)from products.warehouse_sources.backend.temporal.data_imports.sources.clickhouse.source import (_REDIRECTED,+ _TEMPORARILY_UNAVAILABLE,GENERIC_CONNECTION_ERROR,ClickHouseSource,)@@ -413,6 +414,15 @@ class TestClickHouseSourceRetryableErrors:retryable = source.get_retryable_errors()assert not any(pattern in error_msg for pattern in retryable)+ def test_bare_gateway_status_is_classified_as_retryable(self, source):+ # A bare HTTP 500 (no X-ClickHouse-Exception-Code header) means a proxy/load balancer in+ # front of ClickHouse failed, not ClickHouse itself — the same transient shape as the+ # already-retryable 502/503/504. Without this, a transient gateway blip would be reported+ # as tracked exception noise on every occurrence instead of silently retried.+ error_msg = "HTTP driver received HTTP status 500, server response: An unexpected error occurred: EOF (for url https://host:8443)"+ retryable = source.get_retryable_errors()+ assert any(pattern in error_msg for pattern in retryable)+class TestGetClientTransientRetry:"""`_get_client` retries a transient connection drop during connect in-process."""@@ -522,6 +532,13 @@ class TestTranslateError:msg = f"HTTP driver received HTTP status {code} (for url https://host:8443)"assert ClickHouseSource._translate_error(msg) == _REDIRECTED+ @pytest.mark.parametrize("code", ["500", "502", "503", "504"])+ def test_gateway_responses_are_temporarily_unavailable(self, code):+ # A bare status with no ClickHouse exception code means a proxy/LB in front of+ # ClickHouse is briefly down, not that the connection details are wrong.+ msg = f"HTTP driver received HTTP status {code} (for url https://host:8443)"+ assert ClickHouseSource._translate_error(msg) == _TEMPORARILY_UNAVAILABLE+class TestGetSchemas:"""Tests `get_schemas` with a fully mocked ClickHouse client."""