: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(convex): retry read timeouts and connection errors within a page fetch (#73232)
Tom Owers482f27fafb89
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/convex/convex.py b/products/warehouse_sources/backend/temporal/data_imports/sources/convex/convex.pyindex f99008ea3f0c..e0a39e251d41 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/convex/convex.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/convex/convex.py@@ -10,6 +10,7 @@ from requests.exceptions import (ChunkedEncodingError,ConnectionError as RequestsConnectionError,HTTPError,+ ReadTimeout,RequestException,)from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_exponential_jitter@@ -110,16 +111,18 @@ _COMPONENT_TABLE_DELIMITER = "."@retry(- retry=retry_if_exception_type(ChunkedEncodingError),+ # ChunkedEncodingError is a mid-stream connection break (after response headers, so+ # _CONVEX_RETRY — a urllib3 Retry, which only covers pre-response failures — never sees it).+ # ReadTimeout/ConnectionError can also reach here after _CONVEX_RETRY exhausts its own+ # (much shorter) backoff; retrying them here too gives large snapshot/delta pages a longer+ # backoff window before failing the whole sync. Every Convex read is an idempotent GET, so a+ # fresh request safely re-fetches the page.+ retry=retry_if_exception_type((ChunkedEncodingError, ReadTimeout, RequestsConnectionError)),stop=stop_after_attempt(5),wait=wait_exponential_jitter(initial=1, max=30),reraise=True,)def _convex_get(url: str, deploy_key: str, params: dict[str, Any], timeout: int) -> Response:- # requests reads the body eagerly (stream=False), so a connection broken mid-chunk surfaces- # here as ChunkedEncodingError — it happens after the response headers, so _CONVEX_RETRY (a- # urllib3 Retry, which only covers pre-response failures) never sees it. It's transient and- # every Convex read is an idempotent GET, so a fresh request re-fetches the page.return make_tracked_session(retry=_CONVEX_RETRY).get(url, headers=_headers(deploy_key), params=params, timeout=timeout)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/convex/tests/test_convex.py b/products/warehouse_sources/backend/temporal/data_imports/sources/convex/tests/test_convex.pyindex a9b9f20ed7ea..288c952d1228 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/convex/tests/test_convex.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/convex/tests/test_convex.py@@ -5,7 +5,12 @@ import pytestfrom unittest.mock import MagicMock, Mock, patchfrom parameterized import parameterized-from requests.exceptions import ChunkedEncodingError, HTTPError+from requests.exceptions import (+ ChunkedEncodingError,+ ConnectionError as RequestsConnectionError,+ HTTPError,+ ReadTimeout,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.convex.convex import (@@ -261,15 +266,29 @@ class TestDocumentDeltasResumable:manager.save_state.assert_not_called()-class TestConvexChunkedEncodingRetry:+class TestConvexTransientErrorRetry:+ @parameterized.expand(+ [+ (+ "chunked_encoding",+ ChunkedEncodingError("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)"),+ ),+ ("read_timeout", ReadTimeout("Read timed out. (read timeout=60)")),+ ("connection_error", RequestsConnectionError("Max retries exceeded with url: /api/document_deltas")),+ ]+ )@patch("products.warehouse_sources.backend.temporal.data_imports.sources.convex.convex.make_tracked_session")- def test_document_deltas_retries_on_chunked_encoding_error(self, mock_get: Mock) -> None:- # A connection broken mid-body surfaces as ChunkedEncodingError after the response headers,- # past _CONVEX_RETRY's reach (urllib3 only retries pre-response failures). The reads are- # idempotent GETs, so a fresh request must re-fetch the page rather than fail the sync.+ def test_document_deltas_retries_on_transient_error(+ self, _name: str, transient_error: Exception, mock_get: Mock+ ) -> None:+ # These surface after urllib3's own (much shorter) retry budget is exhausted — a+ # ChunkedEncodingError happens after the response headers, past _CONVEX_RETRY's reach+ # entirely (urllib3 only retries pre-response failures), while ReadTimeout/ConnectionError+ # can still occur once _CONVEX_RETRY's total attempts run out. The reads are idempotent+ # GETs, so a fresh request must re-fetch the page rather than fail the whole sync.manager = _make_manager(can_resume=False)mock_get.return_value.get.side_effect = [- ChunkedEncodingError("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)"),+ transient_error,_make_response({"values": [{"_id": "a"}], "cursor": 30, "hasMore": False}),]