: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(github): retry connection broken mid-stream during import (#66276)
Tom Owersb75821f2f233
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.pyindex a819e3df760e..905a15830292 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py@@ -350,7 +350,16 @@ def _github_retry_wait(state: RetryCallState) -> float:@retry(retry=retry_if_exception_type(- (GithubRetryableError, GitHubRateLimitError, requests.ReadTimeout, requests.ConnectionError)+ (+ GithubRetryableError,+ GitHubRateLimitError,+ requests.ReadTimeout,+ requests.ConnectionError,+ # GitHub can break the connection mid-body on a chunked response, which surfaces as a+ # ChunkedEncodingError (a direct RequestException subclass, not a ConnectionError). It's+ # transient — a fresh GET re-fetches the page — so retry it instead of failing the sync.+ requests.exceptions.ChunkedEncodingError,+ )),stop=stop_after_attempt(5),wait=_github_retry_wait,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_fetch_page.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_fetch_page.pynew file mode 100644index 000000000000..349410d8c428--- /dev/null+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_fetch_page.py@@ -0,0 +1,44 @@+import pytest+from unittest import mock++import requests++from products.warehouse_sources.backend.temporal.data_imports.sources.github import github+++def _ok_response() -> mock.Mock:+ response = mock.Mock(spec=requests.Response)+ response.status_code = 200+ response.ok = True+ response.text = ""+ return response++[email protected](autouse=True)+def _instant_backoff():+ # The retry wait falls back to exponential backoff for ChunkedEncodingError; zero it so the+ # test doesn't actually sleep between attempts.+ with mock.patch.object(github, "_github_backoff_wait", return_value=0.0):+ yield+++def test_fetch_page_retries_chunked_encoding_error():+ session = mock.Mock()+ session.get.side_effect = [requests.exceptions.ChunkedEncodingError("Connection broken"), _ok_response()]++ with mock.patch.object(github, "make_tracked_session", return_value=session):+ response = github._fetch_page("https://api.github.com/repos/o/r/issues", {}, mock.Mock())++ assert response.status_code == 200+ assert session.get.call_count == 2+++def test_fetch_page_reraises_chunked_encoding_error_after_exhausting_retries():+ session = mock.Mock()+ session.get.side_effect = [requests.exceptions.ChunkedEncodingError("Connection broken")] * 5++ with mock.patch.object(github, "make_tracked_session", return_value=session):+ with pytest.raises(requests.exceptions.ChunkedEncodingError):+ github._fetch_page("https://api.github.com/repos/o/r/issues", {}, mock.Mock())++ assert session.get.call_count == 5