: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(warehouse): retry Cloudflare 52x timeouts in shared HTTP policy (#87443)
posthog[bot]e08121355b44
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/http/tests/test_transport.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/http/tests/test_transport.pyindex 238ddccaf29a..c95573fdf28e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/http/tests/test_transport.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/http/tests/test_transport.py@@ -41,3 +41,28 @@ class TestBoundedRetry:# urllib3 rebuilds the Retry via `new()` on each attempt; the cap must survive.assert isinstance(DEFAULT_RETRY, BoundedRetry)assert isinstance(DEFAULT_RETRY.new(), BoundedRetry)++ @parameterized.expand(+ [+ ("rate_limited", 429, True),+ ("bad_gateway", 502, True),+ ("gateway_timeout", 504, True),+ # Cloudflare 52x family — a slow or unreachable origin behind Cloudflare (e.g. Cal.com).+ ("cloudflare_unknown", 520, True),+ ("cloudflare_web_server_down", 521, True),+ ("cloudflare_connection_timeout", 522, True),+ ("cloudflare_origin_unreachable", 523, True),+ ("cloudflare_timeout", 524, True),+ ("cloudflare_dns", 530, True),+ # Not transient: a real 4xx or an origin that answered.+ ("not_implemented", 501, False),+ ("bad_request", 400, False),+ ("ok", 200, False),+ ]+ )+ def test_default_retry_covers_transient_statuses(self, _name: str, status: int, retried: bool) -> None:+ assert DEFAULT_RETRY.is_retry("GET", status) is retried++ def test_default_retry_skips_non_idempotent_methods(self) -> None:+ # A POST is not safe to replay, so even a transient timeout must not be retried.+ assert DEFAULT_RETRY.is_retry("POST", 524) is Falsediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/http/transport.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/http/transport.pyindex dbb2805fac39..8e0f0e2a2788 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/http/transport.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/http/transport.py@@ -67,10 +67,18 @@ class BoundedRetry(Retry):return min(retry_after, self.DEFAULT_BACKOFF_MAX)+# Cloudflare returns the 52x family for a slow or unreachable origin: 520 (Unknown Error), 521 (Web+# Server Down), 522 (Connection Timed Out), 523 (Origin Unreachable), 524 (A Timeout Occurred), plus+# 530 (edge-side DNS hiccup). These are transient like the standard 502/503/504, so retry them the+# same way. A source behind Cloudflare (Cal.com, Convex, DoiT) otherwise records a raw 52x as a+# failure. Retries are safe because only GET/HEAD/OPTIONS are retried; a persistent 52x still+# surfaces after the attempt budget because raise_on_status is False.+CLOUDFLARE_TRANSIENT_STATUSES = (520, 521, 522, 523, 524, 530)+DEFAULT_RETRY = BoundedRetry(total=3,backoff_factor=0.5,- status_forcelist=(429, 500, 502, 503, 504),+ status_forcelist=(429, 500, 502, 503, 504, *CLOUDFLARE_TRANSIENT_STATUSES),allowed_methods=frozenset(["GET", "HEAD", "OPTIONS"]),raise_on_status=False,)