File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed
Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -54,8 +54,10 @@ async def get_or_create_session(self) -> Session:
5454 call ensure_connected on whatever session is active.
5555 """
5656 existing_session = self ._session
57- if not existing_session or existing_session .is_closed ():
57+ if not existing_session or existing_session .is_terminal ():
5858 logger .info ("Creating new session" )
59+ if existing_session :
60+ await existing_session .close ()
5961 new_session = Session (
6062 client_id = self ._client_id ,
6163 server_id = self ._server_id ,
Original file line number Diff line number Diff line change @@ -324,7 +324,7 @@ def unbind_connecting_task() -> None:
324324 if self ._terminating_task :
325325 await self ._terminating_task
326326
327- def is_closed (self ) -> bool :
327+ def is_terminal (self ) -> bool :
328328 """
329329 If the session is in a terminal state.
330330 Do not send messages, do not expect any more messages to be emitted,
@@ -402,12 +402,15 @@ async def close(
402402 self , reason : Exception | None = None , current_state : SessionState | None = None
403403 ) -> None :
404404 """Close the session and all associated streams."""
405- logger .info (
406- f"{ self .session_id } closing session to { self ._server_id } , ws: { self ._ws } "
407- )
408405 if (current_state or self ._state ) in TerminalStates :
406+ while (current_state or self ._state ) != SessionState .CLOSED :
407+ logger .debug ("Session already closing, waiting..." )
408+ await asyncio .sleep (0.2 )
409409 # already closing
410410 return
411+ logger .info (
412+ f"{ self .session_id } closing session to { self ._server_id } , ws: { self ._ws } "
413+ )
411414 self ._state = SessionState .CLOSING
412415
413416 # We're closing, so we need to wake up...
You can’t perform that action at this time.
0 commit comments