Skip to content

: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.

fix(data-imports): cap poll backoff exponent to avoid float overflow (#79379)

Tom Owers7d4007b6712f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.py
index 71c324fa576e..5bfd8105ff30 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.py
@@ -44,6 +44,13 @@ SHUTDOWN_DRAIN_TIMEOUT_SECONDS = 30.0
# whole fleet hammer a degraded queue DB in lockstep.
POLL_BACKOFF_MAX_SECONDS = 30.0
+# Ceiling on the backoff exponent. A prolonged queue-DB outage drives the failure
+# count into the thousands, and 2 ** (failures - 1) then overflows float when
+# multiplied by the interval, before min() can clamp to POLL_BACKOFF_MAX_SECONDS.
+# 2 ** 32 already dwarfs the cap for any real poll interval, so doubling past here
+# only risks the overflow without changing the (already saturated) result.
+POLL_BACKOFF_MAX_DOUBLINGS = 32
+
# Per-poll fetch cap multiplier: fetch at most (free slots x this) batches so a poll
# never leases far more groups than it can dispatch. Runs average ~2 batches per
# group (batch 0 + final), so x3 gives headroom for multi-batch runs without
@@ -1077,7 +1084,8 @@ class BatchConsumer:
gets exponentially less pressure and the fleet's retries desynchronize."""
base = self._config.poll_interval_seconds
failures = max(self._consecutive_poll_failures, 1)
- backoff = min(base * 2 ** (failures - 1), POLL_BACKOFF_MAX_SECONDS)
+ exponent = min(failures - 1, POLL_BACKOFF_MAX_DOUBLINGS)
+ backoff = min(base * 2**exponent, POLL_BACKOFF_MAX_SECONDS)
return backoff + random.uniform(0, base)
def _report_health(self) -> None:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py
index 85d2ed16872f..25fa5e202a2b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py
@@ -879,6 +879,10 @@ class TestPollBackoff:
assert consumer._poll_retry_delay() == 8.0
consumer._consecutive_poll_failures = 20 # far past the cap
assert consumer._poll_retry_delay() == 30.0 # POLL_BACKOFF_MAX_SECONDS
+ # A prolonged outage grows the count without bound; 2 ** (failures - 1) used
+ # to overflow float here and crash the consumer instead of returning the cap.
+ consumer._consecutive_poll_failures = 5000
+ assert consumer._poll_retry_delay() == 30.0
def test_jitter_is_added_within_one_interval(self):
consumer = _make_consumer(poll_interval_seconds=2.0)