Skip to content

Commit 211bbeb

Browse files
Terminate _serve early if we are terminal
1 parent 907e08b commit 211bbeb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/replit_river/v2/session.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ async def _setup_heartbeat(
11051105
while True:
11061106
while (state := get_state()) in ConnectingStates:
11071107
await block_until_connected()
1108+
11081109
if state in TerminalStates:
11091110
logger.debug(
11101111
"Session is closed, no need to send heartbeat, state : "
@@ -1156,9 +1157,17 @@ async def _serve(
11561157
while our_task and not our_task.cancelling() and not our_task.cancelled():
11571158
logger.debug(f"_serve loop count={idx}")
11581159
idx += 1
1159-
while (ws := get_ws()) is None or get_state() in ConnectingStates:
1160+
while (ws := get_ws()) is None or (state := get_state()) in ConnectingStates:
11601161
logger.debug("_handle_messages_from_ws spinning while connecting")
11611162
await block_until_connected()
1163+
1164+
if state in TerminalStates:
1165+
logger.debug(
1166+
f"Session is {state}, shut down _serve",
1167+
)
1168+
# session is closing / closed, no need to serve anymore
1169+
break
1170+
11621171
logger.debug(
11631172
"%s start handling messages from ws %s",
11641173
"client",

0 commit comments

Comments
 (0)