: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(warehouse-sources): retry a Framer handshake that closes before an HTTP response (#83539)
Tom Owersd0569cdff46a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/framer.py b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/framer.pyindex 84e53e9127a7..c5bef2e9605d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/framer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/framer.py@@ -18,7 +18,7 @@ from typing import Any, Optional, Protocolfrom urllib.parse import unquote, urlencode, urljoin, urlsplitfrom structlog.types import FilteringBoundLogger-from websockets.exceptions import ConnectionClosed, InvalidStatus+from websockets.exceptions import ConnectionClosed, InvalidMessage, InvalidStatusfrom websockets.headers import build_authorization_basicfrom websockets.sync.client import connect as websocket_connectfrom websockets.uri import Proxy, get_proxy, parse_proxy, parse_uri@@ -183,6 +183,13 @@ class FramerClient:if status in (401, 403):raise FramerAPIError("Framer rejected the API key", code="UNAUTHORIZED") from eraise FramerAPIError(f"Connection rejected with HTTP {status}", code="INTERNAL", retryable=True) from e+ except InvalidMessage as e:+ # The server accepted the TCP/TLS connection but closed it before sending a+ # parseable HTTP response (e.g. an EOF while reading the status line) — a+ # headless-pool hiccup on Framer's side, not a credential or config problem.+ raise FramerAPIError(+ f"Connection closed during handshake: {e}", code="CONNECTION_CLOSED", retryable=True+ ) from edeadline = time.monotonic() + CONNECT_TIMEOUT_SECONDSwhile True:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer.py b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer.pyindex 1ce9b406356a..86b140cc1f8f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer.py@@ -11,6 +11,7 @@ from typing import Any, Optional, castimport pytestfrom parameterized import parameterized+from websockets.exceptions import InvalidMessagefrom products.warehouse_sources.backend.temporal.data_imports.sources.framer import devaluefrom products.warehouse_sources.backend.temporal.data_imports.sources.framer.framer import (@@ -278,6 +279,16 @@ class TestFramer:client.connect()assert exc_info.value.retryable+ def test_client_wraps_handshake_eof_as_retryable(self) -> None:+ def connect_fn(*args: Any, **kwargs: Any) -> Any:+ raise InvalidMessage("did not receive a valid HTTP response")++ client = FramerClient(PROJECT_ID, "test-key", protocol_version="0.1.29", connect_fn=connect_fn)+ with pytest.raises(FramerAPIError) as exc_info:+ client.connect()+ assert exc_info.value.code == "CONNECTION_CLOSED"+ assert exc_info.value.retryable+def test_client_raises_on_method_error(self) -> None:server = FakeFramerServer()client = make_client(server)