From d1d9f390e9080fc304e8faf761ce9465067f971d Mon Sep 17 00:00:00 2001 From: Henry Su Date: Sun, 25 Oct 2026 23:04:39 -0500 Subject: [PATCH 1/2] test(realtime): reproduce ignored opening timeout Refs #1836 --- src/realtime/tests/test_connection_timeout.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/realtime/tests/test_connection_timeout.py diff --git a/src/realtime/tests/test_connection_timeout.py b/src/realtime/tests/test_connection_timeout.py new file mode 100644 index 000000000..ece8fc94b --- /dev/null +++ b/src/realtime/tests/test_connection_timeout.py @@ -0,0 +1,32 @@ +from unittest.mock import AsyncMock, patch + +import pytest + +from realtime import AsyncRealtimeClient + + +@pytest.mark.asyncio +@pytest.mark.parametrize("timeout", [1, 30]) +async def test_connect_applies_configured_opening_timeout(timeout: int) -> None: + client = AsyncRealtimeClient("ws://localhost/realtime/v1", timeout=timeout) + + with ( + patch("realtime._async.client.connect", new_callable=AsyncMock) as connect, + patch.object(client, "_on_connect", new_callable=AsyncMock), + ): + await client.connect() + + connect.assert_awaited_once_with(client.endpoint_url(), open_timeout=timeout) + + +@pytest.mark.asyncio +async def test_connect_applies_default_opening_timeout() -> None: + client = AsyncRealtimeClient("ws://localhost/realtime/v1") + + with ( + patch("realtime._async.client.connect", new_callable=AsyncMock) as connect, + patch.object(client, "_on_connect", new_callable=AsyncMock), + ): + await client.connect() + + connect.assert_awaited_once_with(client.endpoint_url(), open_timeout=10) From 8336f9a87a2a1cf0528f1a62ab14425201e40a35 Mon Sep 17 00:00:00 2001 From: Henry Su Date: Sun, 25 Oct 2026 23:04:40 -0500 Subject: [PATCH 2/2] fix(realtime): honor the WebSocket opening timeout Fixes #1836 --- src/realtime/src/realtime/_async/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/realtime/src/realtime/_async/client.py b/src/realtime/src/realtime/_async/client.py index 5721054d3..fc037b8c0 100644 --- a/src/realtime/src/realtime/_async/client.py +++ b/src/realtime/src/realtime/_async/client.py @@ -166,7 +166,7 @@ async def connect(self) -> None: while retries < self.max_retries: try: - ws = await connect(endpoint_url) + ws = await connect(endpoint_url, open_timeout=self.timeout) self._ws_connection = ws logger.debug("WebSocket connection established successfully") return await self._on_connect()