Skip to content

Commit 76fe826

Browse files
Rely on _terminating_task explicitly
1 parent 511c5ca commit 76fe826

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

src/replit_river/v2/session.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ class Session[HandshakeMetadata]:
169169

170170
# Terminating
171171
_terminating_task: asyncio.Task[None] | None
172-
_closing_waiter: asyncio.Event | None
173172

174173
def __init__(
175174
self,
@@ -229,7 +228,6 @@ def __init__(
229228

230229
# Terminating
231230
self._terminating_task = None
232-
self._closing_waiter = None
233231

234232
self._start_recv_from_ws()
235233
self._start_buffered_message_sender()
@@ -393,11 +391,11 @@ async def close(
393391
reason: Exception | None = None,
394392
) -> None:
395393
"""Close the session and all associated streams."""
396-
if self._closing_waiter:
394+
if self._terminating_task:
397395
try:
398396
logger.debug("Session already closing, waiting...")
399397
async with asyncio.timeout(SESSION_CLOSE_TIMEOUT_SEC):
400-
await self._closing_waiter.wait()
398+
await self._terminating_task
401399
except asyncio.TimeoutError:
402400
logger.warning(
403401
f"Session took longer than {SESSION_CLOSE_TIMEOUT_SEC} "
@@ -436,7 +434,6 @@ async def do_close() -> None:
436434
f"ws: {self._ws}"
437435
)
438436
self._state = SessionState.CLOSING
439-
self._closing_waiter = asyncio.Event()
440437

441438
# We're closing, so we need to wake up...
442439
# ... tasks waiting for connection to be established
@@ -502,10 +499,6 @@ async def do_close() -> None:
502499
# This will get us GC'd, so this should be the last thing.
503500
self._close_session_callback(self)
504501

505-
# Release waiters, then release the event
506-
self._closing_waiter.set()
507-
self._closing_waiter = None
508-
509502
if self._terminating_task:
510503
return self._terminating_task
511504

0 commit comments

Comments
 (0)