: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(google_sheets): retry connection resets during sheet download (#69330)
Tom Owers06759627be20
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/google_sheets.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/google_sheets.pyindex 9c161a948f77..f59f4f2bc328 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/google_sheets.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/google_sheets.py@@ -120,12 +120,23 @@ def _retry_on_transient_api_error(execute: Callable[[], T]) -> T:while True:try:return execute()- except (gspread.exceptions.APIError, requests.exceptions.ConnectionError, requests.exceptions.Timeout) as e:+ except (+ gspread.exceptions.APIError,+ requests.exceptions.ConnectionError,+ requests.exceptions.Timeout,+ requests.exceptions.ChunkedEncodingError,+ ) as e:# A dropped connection or read timeout is raised by `requests` before gspread can wrap# it in an APIError, so the status-code check never sees it, and the tracked adapter's# transport retries are already spent by the time it reaches us. It's a transient# network blip, so retry inline like a 5xx; APIErrors still gate on their status. Once# the budget is spent, let it bubble so Temporal retries the activity.+ #+ # `ChunkedEncodingError` is listed separately because a connection reset mid-download+ # surfaces as one: `requests` catches the underlying urllib3 `ProtocolError` while+ # streaming the response body and re-raises it as `ChunkedEncodingError`, which is a+ # sibling of `ConnectionError` in the `requests` hierarchy (not a subclass), so the+ # `ConnectionError` entry above would not catch it.is_retryable = _is_retryable_api_error(e) if isinstance(e, gspread.exceptions.APIError) else Trueif not is_retryable or attempts >= max_attempts:raisediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/tests/test_google_sheets.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/tests/test_google_sheets.pyindex 5aa6cc4565a9..070d1a29d65c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/tests/test_google_sheets.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/tests/test_google_sheets.py@@ -326,6 +326,12 @@ def test_retry_on_transient_api_error_does_not_retry_non_transient():requests.exceptions.ConnectionError("Connection aborted."),requests.exceptions.ReadTimeout("Read timed out. (read timeout=120.0)"),requests.exceptions.ConnectTimeout("Connection timed out."),+ # A connection reset mid-download surfaces as ChunkedEncodingError, which is a sibling of+ # ConnectionError in the requests hierarchy (not a subclass), so it must be caught explicitly.+ requests.exceptions.ChunkedEncodingError(+ "('Connection broken: ConnectionResetError(104, 'Connection reset by peer')', "+ "ConnectionResetError(104, 'Connection reset by peer'))"+ ),],)def test_retry_on_transient_api_error_retries_network_error_then_succeeds(error):@@ -346,6 +352,7 @@ def test_retry_on_transient_api_error_retries_network_error_then_succeeds(error)[requests.exceptions.ConnectionError("Connection aborted."),requests.exceptions.ReadTimeout("Read timed out. (read timeout=120.0)"),+ requests.exceptions.ChunkedEncodingError("Connection broken: ConnectionResetError(104, ...)"),],)def test_retry_on_transient_api_error_bubbles_network_error_after_max_retries(error):