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(shopify): retry transient connection errors during graphql reads (#65777)

Tom Owers944611620092
diff --git a/posthog/temporal/data_imports/sources/shopify/shopify.py b/posthog/temporal/data_imports/sources/shopify/shopify.py
index d71a60e39679..9c7bd8840370 100644
--- a/posthog/temporal/data_imports/sources/shopify/shopify.py
+++ b/posthog/temporal/data_imports/sources/shopify/shopify.py
@@ -174,7 +174,13 @@ def _make_paginated_shopify_request(
endpoint_config = ENDPOINT_CONFIGS.get(graphql_object.name)
@retry(
- retry=retry_if_exception_type(ShopifyRetryableError),
+ # Transient network failures (proxy/egress hiccups, connect/read timeouts) surface from
+ # `sess.post` as requests ConnectionError/Timeout — e.g. a 504 from the egress proxy tunnel.
+ # They're retryable like a 5xx, so reissue the request with backoff instead of failing the
+ # whole import. ConnectionError covers ProxyError; Timeout covers connect/read timeouts.
+ retry=retry_if_exception_type(
+ (ShopifyRetryableError, requests.exceptions.ConnectionError, requests.exceptions.Timeout)
+ ),
stop=stop_after_attempt(5),
wait=_shopify_retry_wait,
reraise=True,
diff --git a/posthog/temporal/data_imports/sources/shopify/tests/test_rate_limit_retry.py b/posthog/temporal/data_imports/sources/shopify/tests/test_rate_limit_retry.py
index 0861f29e3c03..c3291d894ec1 100644
--- a/posthog/temporal/data_imports/sources/shopify/tests/test_rate_limit_retry.py
+++ b/posthog/temporal/data_imports/sources/shopify/tests/test_rate_limit_retry.py
@@ -1,6 +1,7 @@
import pytest
from unittest.mock import MagicMock, patch
+import requests
from requests.exceptions import ChunkedEncodingError
from tenacity import Future, RetryCallState, Retrying
@@ -116,6 +117,32 @@ def test_request_retries_connection_broken_mid_stream_then_succeeds(_mock_sleep)
assert sess.post.call_count == 2
+ "transient_error",
+ [
+ # The observed failure: a 504 from the egress proxy tunnel surfaces as ProxyError.
+ requests.exceptions.ProxyError("Tunnel connection failed: 504 Gateway timeout"),
+ requests.exceptions.ConnectionError("Connection reset by peer"),
+ requests.exceptions.ReadTimeout("Read timed out"),
+ ],
+)
+@patch("tenacity.nap.time.sleep")
+def test_request_retries_transient_connection_error_then_succeeds(_mock_sleep, transient_error):
+ # Transient network errors escaping `post` (proxy hiccup, reset, timeout) are reissued
+ # rather than failing the import.
+ sess = MagicMock()
+ sess.post.side_effect = [transient_error, _ok_page()]
+
+ batches = list(
+ _make_paginated_shopify_request(
+ "https://example.invalid/graphql", sess, SHOPIFY_GRAPHQL_OBJECTS[ABANDONED_CHECKOUTS], MagicMock()
+ )
+ )
+
+ assert batches == [[{"id": "1"}]]
+ assert sess.post.call_count == 2
+
+
@patch("tenacity.nap.time.sleep")
def test_request_reraises_retryable_after_persistent_connection_broken(_mock_sleep):
sess = MagicMock()
@@ -129,3 +156,18 @@ def test_request_reraises_retryable_after_persistent_connection_broken(_mock_sle
)
assert sess.post.call_count == 5
+
+
+@patch("tenacity.nap.time.sleep")
+def test_request_reraises_after_persistent_connection_error(_mock_sleep):
+ sess = MagicMock()
+ sess.post.side_effect = requests.exceptions.ProxyError("Tunnel connection failed: 504 Gateway timeout")
+
+ with pytest.raises(requests.exceptions.ProxyError):
+ list(
+ _make_paginated_shopify_request(
+ "https://example.invalid/graphql", sess, SHOPIFY_GRAPHQL_OBJECTS[ABANDONED_CHECKOUTS], MagicMock()
+ )
+ )
+
+ assert sess.post.call_count == 5