@@ -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,14 +499,11 @@ 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
512- return asyncio .create_task (do_close ())
505+ self ._terminating_task = asyncio .create_task (do_close ())
506+ return self ._terminating_task
513507
514508 def _start_buffered_message_sender (
515509 self ,
0 commit comments