Skip to content

Commit caeea3e

Browse files
Add a direct timeout for ws.recv
1 parent e0776de commit caeea3e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/replit_river/v2/session.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,9 @@ async def websocket_closed_callback() -> None:
11551155
)
11561156

11571157
try:
1158-
data = await ws.recv(decode=False)
1158+
timeout = handshake_deadline_ms - get_current_time() / 1000.0
1159+
async with asyncio.timeout(timeout):
1160+
data = await ws.recv(decode=False)
11591161
except ConnectionClosedOK:
11601162
# In the case of a normal connection closure, we defer to
11611163
# the outer loop to determine next steps.
@@ -1172,6 +1174,16 @@ async def websocket_closed_callback() -> None:
11721174
ERROR_HANDSHAKE,
11731175
"Handshake failed, conn closed while waiting for response",
11741176
) from e
1177+
except asyncio.CancelledError as e:
1178+
logger.debug(
1179+
"_do_ensure_connected: Response timeout while waiting "
1180+
"for handshake response",
1181+
exc_info=True,
1182+
)
1183+
raise RiverException(
1184+
ERROR_HANDSHAKE,
1185+
"Handshake failed, timeout while waiting for response",
1186+
) from e
11751187

11761188
try:
11771189
response_msg = parse_transport_msg(data)

0 commit comments

Comments
 (0)