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(linear): retry transient network errors during import (#64433)

Tom Owersf0bd3b27d52d
diff --git a/posthog/temporal/data_imports/sources/linear/linear.py b/posthog/temporal/data_imports/sources/linear/linear.py
index 0d942abaea68..6b14db249539 100644
--- a/posthog/temporal/data_imports/sources/linear/linear.py
+++ b/posthog/temporal/data_imports/sources/linear/linear.py
@@ -90,7 +90,13 @@ def _make_paginated_request(
reraise=True,
)
def execute(variables: dict[str, Any]) -> dict:
- response = sess.post(LINEAR_API_URL, json={"query": query, "variables": variables}, timeout=60)
+ try:
+ response = sess.post(LINEAR_API_URL, json={"query": query, "variables": variables}, timeout=60)
+ except (requests.ConnectionError, requests.Timeout) as e:
+ # The session's urllib3 Retry only covers idempotent methods, so Linear's POSTs get no
+ # transport-level retry. Route transient network failures (read timeout, connection reset)
+ # through the same backoff path as 5xx/429 instead of failing the whole activity on one blip.
+ raise LinearRetryableError(f"Linear: transient network error - {e}")
if response.status_code >= 500:
raise LinearRetryableError(f"Linear: server error {response.status_code}")
diff --git a/posthog/temporal/data_imports/sources/linear/test_linear.py b/posthog/temporal/data_imports/sources/linear/test_linear.py
index 38729b1eaed6..c53f85f22214 100644
--- a/posthog/temporal/data_imports/sources/linear/test_linear.py
+++ b/posthog/temporal/data_imports/sources/linear/test_linear.py
@@ -5,6 +5,7 @@ from typing import Any, cast
import pytest
from unittest.mock import MagicMock, patch
+import requests
from parameterized import parameterized
from tenacity import Future, RetryCallState
@@ -225,6 +226,68 @@ class TestMakePaginatedRequest:
assert session.post.call_count == 5
+ @parameterized.expand(
+ [
+ ("read_timeout", requests.exceptions.ReadTimeout("Read timed out. (read timeout=60)")),
+ ("connection_reset", requests.exceptions.ConnectionError("Connection aborted")),
+ ]
+ )
+ @patch("time.sleep", return_value=None)
+ @patch("posthog.temporal.data_imports.sources.linear.linear.make_tracked_session")
+ def test_transient_network_error_is_retried_then_succeeds(
+ self,
+ _name: str,
+ transient_exc: Exception,
+ mock_session_cls: MagicMock,
+ _mock_sleep: MagicMock,
+ ) -> None:
+ # Linear's POSTs get no transport-level retry, so a transient network error must be folded
+ # into the application-level backoff rather than escaping on the first attempt.
+ session = MagicMock()
+ session.post.side_effect = [transient_exc, _make_response([{"id": "a"}], False, None)]
+ mock_session_cls.return_value = session
+
+ manager = _make_resumable_manager()
+ logger = MagicMock()
+
+ pages = list(
+ _make_paginated_request(
+ access_token="tok",
+ endpoint_name="issues",
+ logger=logger,
+ resumable_source_manager=manager,
+ )
+ )
+
+ assert pages == [[{"id": "a"}]]
+ assert session.post.call_count == 2
+
+ @patch("time.sleep", return_value=None)
+ @patch("posthog.temporal.data_imports.sources.linear.linear.make_tracked_session")
+ def test_persistent_network_error_raises_retryable_error(
+ self, mock_session_cls: MagicMock, _mock_sleep: MagicMock
+ ) -> None:
+ session = MagicMock()
+ session.post.side_effect = [
+ requests.exceptions.ReadTimeout("Read timed out. (read timeout=60)") for _ in range(5)
+ ]
+ mock_session_cls.return_value = session
+
+ manager = _make_resumable_manager()
+ logger = MagicMock()
+
+ with pytest.raises(LinearRetryableError):
+ list(
+ _make_paginated_request(
+ access_token="tok",
+ endpoint_name="issues",
+ logger=logger,
+ resumable_source_manager=manager,
+ )
+ )
+
+ assert session.post.call_count == 5
+
class TestRateLimitBackoff:
@parameterized.expand(
@@ -338,6 +401,10 @@ class TestLinearSourceNonRetryableErrors:
("transient_500", "500 Server Error for url: https://api.linear.app/graphql"),
("rate_limited", "Linear: rate limited (429)"),
("graphql_error", "Linear GraphQL error: Something failed"),
+ (
+ "read_timeout",
+ "Linear: transient network error - HTTPSConnectionPool(host='api.linear.app', port=443): Read timed out. (read timeout=60)",
+ ),
]
)
def test_non_retryable_errors_does_not_match_transient(self, _name: str, observed_error: str) -> None: