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(linkedin_ads): retry connection resets during response streaming (#102040)

Tom Owers1c4aaffffb5f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/client.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/client.py
index cf0f8aced7ce..ab21916d9321 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/client.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/client.py
@@ -305,7 +305,14 @@ class LinkedinAdsClient:
return RESOURCE_SCHEMAS[resource]["field_names"]
@retry(
- retry=retry_if_exception_type((LinkedinAdsRetryableError, requests.ConnectionError, requests.Timeout)),
+ retry=retry_if_exception_type(
+ (
+ LinkedinAdsRetryableError,
+ requests.ConnectionError,
+ requests.Timeout,
+ requests.exceptions.ChunkedEncodingError,
+ )
+ ),
stop=stop_after_attempt(5),
wait=_retry_wait,
reraise=True,
@@ -316,7 +323,10 @@ class LinkedinAdsClient:
LinkedIn's edge occasionally drops TLS connections mid-handshake (SSLEOFError) or
returns 504s; those surface here as `requests.ConnectionError` / `requests.Timeout`
from the underlying requests.Session, or as a non-2xx response we convert to
- `LinkedinAdsRetryableError`. Non-retryable 4xx responses still raise immediately.
+ `LinkedinAdsRetryableError`. A connection reset mid-response-body surfaces instead as
+ `requests.exceptions.ChunkedEncodingError`, which — unlike `SSLError` — isn't a
+ `ConnectionError` subclass, so it needs its own entry here. Non-retryable 4xx responses
+ still raise immediately.
429s are split by throttle window: a DAY throttle is the per-member/app daily call budget
(resets only at midnight UTC) and raises a non-retryable `LinkedinAdsDailyRateLimitError`
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_client.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_client.py
index d3d119343424..4fdffa684555 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_client.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_client.py
@@ -366,6 +366,11 @@ class TestLinkedinAdsClient:
3,
id="connection_error",
),
+ pytest.param(
+ lambda: requests.exceptions.ChunkedEncodingError("Connection broken: ConnectionResetError"),
+ 3,
+ id="chunked_encoding_error",
+ ),
pytest.param(
lambda: requests.exceptions.Timeout("read timed out"),
3,