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(notion): stop exhausted connection retries reporting as error-tracking noise (#78636)

Tom Owers4a39c75b85d9
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/source.py
index 895f8fc38ca4..f426aa5c9a2c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/source.py
@@ -55,13 +55,16 @@ class NotionSource(ResumableSource[NotionSourceConfig, NotionResumeConfig]):
# tenacity-wrapped _request, which honors Notion's Retry-After on 429s); if those retries
# still exhaust, the failure is transient and self-recovering, so let Temporal retry the
# activity without surfacing it as tracked exception noise.
- #
- # A dropped/reset connection (SSL handshake failure, connection reset, proxy error) is
- # retried by that same tenacity decorator via requests.ConnectionError. urllib3 wraps all of
- # these in a MaxRetryError before requests re-raises them as the specific subclass, so they
- # share this message regardless of the underlying reason. Same self-recovering reasoning
- # applies once that budget exhausts.
- return {"Notion API error (retryable)", "Notion rate limited", "Max retries exceeded with url"}
+ return {
+ "Notion API error (retryable)",
+ "Notion rate limited",
+ # `_request`'s tenacity retry also covers `requests.ConnectionError` (which
+ # `requests.exceptions.SSLError` subclasses) and `requests.ReadTimeout`. urllib3
+ # wraps both as "... Max retries exceeded with url: ..." regardless of the underlying
+ # cause (TLS EOF, refused connection, timeout), so match that stable prefix rather
+ # than the per-request URL or nested error id.
+ "Max retries exceeded with url",
+ }
@property
def get_source_config(self) -> SourceConfig:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/tests/test_notion_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/tests/test_notion_source.py
index 045d60e65d5d..f4bf08590d8e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/notion/tests/test_notion_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/notion/tests/test_notion_source.py
@@ -166,13 +166,21 @@ class TestNotionSource:
"/v1/comments?block_id=abc&page_size=100 (Caused by SSLError(SSLEOFError(8, "
"'[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1032)')))",
),
+ (
+ "read_timeout_after_tenacity_exhausted",
+ "HTTPSConnectionPool(host='api.notion.com', port=443): Max retries exceeded with url: "
+ "/v1/search (Caused by ReadTimeoutError(\"HTTPSConnectionPool(host='api.notion.com', "
+ 'port=443): Read timed out."))',
+ ),
]
)
def test_retryable_marker_matches_raised_message(self, _name: str, error_message: str) -> None:
- # notion.py's _request raises these messages after tenacity's internal retries exhaust
- # (5xx, 429 rate limits, and dropped connections routed through requests.ConnectionError);
- # matching them here keeps that self-recovering failure out of error tracking as noise
- # instead of being logged as an unclassified exception.
+ # notion.py's _request raises the 5xx and rate-limit messages after tenacity's internal
+ # retries exhaust, and also lets requests.ConnectionError (which SSLError subclasses) and
+ # requests.ReadTimeout through that same retry loop; once the budget exhausts, urllib3
+ # wraps them as a "Max retries exceeded with url" message. Matching them all keeps these
+ # self-recovering failures out of error tracking as noise instead of being logged as an
+ # unclassified exception.
markers = self.source.get_retryable_errors()
assert markers
assert any(marker in error_message for marker in markers)