Skip to content

Commit 08c4ba7

Browse files
Adding some more safeguards
1 parent b49a73f commit 08c4ba7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/replit_river/v2/session.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,11 +1090,17 @@ async def _do_ensure_connected[HandshakeMetadata](
10901090
get_current_time() + transport_options.handshake_timeout_ms / 1000
10911091
)
10921092

1093-
while rate_limiter.has_budget(client_id):
1093+
while (
1094+
rate_limiter.has_budget(client_id)
1095+
and get_current_time() < handshake_deadline_ms
1096+
):
10941097
if (state := get_state()) in TerminalStates or state in ActiveStates:
10951098
logger.info(f"_do_ensure_connected stopping due to state={state}")
10961099
break
10971100

1101+
if (task := asyncio.current_task()) and task.cancelled():
1102+
break
1103+
10981104
if attempt_count > 0:
10991105
logger.info(f"Retrying build handshake number {attempt_count} times")
11001106
attempt_count += 1

tests/v2/test_v2_session_lifecycle.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def trigger_close(
5555
nonlocal ws_close
5656

5757
closing_event = asyncio.Event()
58+
5859
async def _do_close() -> None:
5960
signal_closing()
6061
await task_manager.cancel_all_tasks()
@@ -64,6 +65,7 @@ async def _do_close() -> None:
6465
await ws.close()
6566
become_closed()
6667
closing_event.set()
68+
6769
ws_close = asyncio.create_task(_do_close())
6870

6971
return closing_event

0 commit comments

Comments
 (0)