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(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.py
index 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, Protocol
from urllib.parse import unquote, urlencode, urljoin, urlsplit
from structlog.types import FilteringBoundLogger
-from websockets.exceptions import ConnectionClosed, InvalidStatus
+from websockets.exceptions import ConnectionClosed, InvalidMessage, InvalidStatus
from websockets.headers import build_authorization_basic
from websockets.sync.client import connect as websocket_connect
from 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 e
raise 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 e
deadline = time.monotonic() + CONNECT_TIMEOUT_SECONDS
while 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.py
index 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, cast
import pytest
from parameterized import parameterized
+from websockets.exceptions import InvalidMessage
from products.warehouse_sources.backend.temporal.data_imports.sources.framer import devalue
from 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)