: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): treat egress proxy connect timeouts as transient (#87568)
Tom Owersfa3bb122fd20
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 03b7d40240b7..f3b781a1f1a9 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@@ -150,6 +150,14 @@ _TRANSIENT_CONNECT_DROP_SUBSTRINGS = (# HTTP statuses keep their existing handling (404 is non-retryable in the# source, 5xx stay retryable via Temporal)."returned response code 429",+ # urllib3 couldn't open the TCP connection to our own egress proxy at all — it never got far+ # enough to attempt a CONNECT tunnel — and wraps the raw socket timeout as+ # `ProxyError('Cannot connect to proxy.', TimeoutError('timed out'))`. This is our proxy+ # being briefly unreachable, not a customer config problem, so a fresh attempt recovers.+ # Matching the full inner exception keeps this distinct from `Tunnel connection failed:+ # 407` above, which wraps the same "Cannot connect to proxy." prefix around a deterministic+ # proxy-auth response and must stay non-retryable.+ "Cannot connect to proxy.', TimeoutError('timed out')",)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 0d3b5f405472..321340727fe5 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@@ -360,6 +360,10 @@ class ClickHouseSource(SimpleSource[ClickHouseSourceConfig], SSHTunnelMixin, Val# entry covers the case where the server stays saturated past all in-process# attempts, so Temporal's own retry — with a fresh backoff budget — isn't noise."TOO_MANY_SIMULTANEOUS_QUERIES",+ # `_get_client` already retries this in-process (see `_TRANSIENT_CONNECT_DROP_SUBSTRINGS`+ # in clickhouse.py); this entry covers the case where our own egress proxy stays+ # unreachable past all in-process attempts, so Temporal's retry isn't noise.+ "Cannot connect to proxy.', TimeoutError('timed out')",}@contextmanagerdiff --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 19cbc01c3a1d..ed31dd5331d9 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@@ -739,6 +739,11 @@ class TestClickHouseSourceRetryableErrors:"HTTPDriver for https://play.clickhouse.com:8443 received ClickHouse error code 202\n ""Code: 202. DB::Exception: Too many simultaneous queries for all users. Current: 500, ""maximum: 500. (TOO_MANY_SIMULTANEOUS_QUERIES) (version 24.8.1.1 (official build))",+ # The exact wrapped message that reached error tracking: our own egress proxy was+ # unreachable past all of `_get_client`'s in-process connect retries.+ "Error HTTPSConnectionPool(host='play.clickhouse.com', port=8443): Max retries exceeded "+ "with url: /? (Caused by ProxyError('Cannot connect to proxy.', TimeoutError('timed out'))) "+ "executing HTTP request attempt 1 (https://play.clickhouse.com:8443)",],)def test_transient_errors_are_retryable(self, source, error_msg):@@ -756,6 +761,17 @@ class TestClickHouseSourceRetryableErrors:retryable = source.get_retryable_errors()assert not any(pattern in error_msg for pattern in retryable)+ def test_proxy_auth_failure_is_not_classified_as_retryable(self, source):+ # A 407 wraps the same "Cannot connect to proxy." prefix as the TCP-connect timeout above,+ # but it's a deterministic proxy-auth misconfiguration, not a transient blip.+ error_msg = (+ "Error HTTPSConnectionPool(host='play.clickhouse.com', port=8443): Max retries exceeded "+ "with url: /? (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection "+ "failed: 407 Proxy Authentication Required')))"+ )+ retryable = source.get_retryable_errors()+ assert not any(pattern in error_msg for pattern in retryable)+class TestIsTransientConnectDrop:@pytest.mark.parametrize(@@ -778,6 +794,11 @@ class TestIsTransientConnectDrop:# HTTP 429 rate-limit at connect time — clickhouse-connect doesn't# retry the client-construction probe, so we retry it in-process."HTTPDriver for https://host:8443 returned response code 429",+ # The exact wrapped message that reached error tracking: urllib3 couldn't open a+ # TCP connection to our own egress proxy before ever attempting a CONNECT tunnel.+ "Error HTTPSConnectionPool(host='h', port=8443): Max retries exceeded with url: /? "+ "(Caused by ProxyError('Cannot connect to proxy.', TimeoutError('timed out'))) "+ "executing HTTP request attempt 1",],)def test_matches_transient_drops(self, message):@@ -792,6 +813,10 @@ class TestIsTransientConnectDrop:"HTTPDriver for https://host:8443 returned response code 404",# A proxy 407 is a deterministic auth-config failure, not a transient gateway blip."Tunnel connection failed: 407 Proxy Authentication Required",+ # A 407 reaches us wrapped in the same "Cannot connect to proxy." prefix as the TCP-connect+ # timeout above — it must not become transient just because it shares that prefix.+ "(Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: "+ "407 Proxy Authentication Required')))",],)def test_does_not_match_deterministic_failures(self, message):