@@ -239,7 +239,7 @@ async def _handle_ws(self, websocket) -> None:
239239 session_ids = set ()
240240 for sid in list (session_ids ):
241241 try :
242- await self ._cleanup_voice_session (sid )
242+ await self ._cleanup_voice_session (sid , VoiceEndReason . REMOTE )
243243 except Exception : # pylint: disable=W0718
244244 _LOG .exception (
245245 "[%s] WS: Error during voice session cleanup for %s" ,
@@ -543,7 +543,9 @@ async def _on_remote_voice_end(self, _websocket, msg: RemoteVoiceEnd) -> None:
543543 session_id = 0 # FIXME(voice) until core is fixed
544544 await self ._cleanup_voice_session (session_id )
545545
546- async def _cleanup_voice_session (self , session_id : int ) -> None :
546+ async def _cleanup_voice_session (
547+ self , session_id : int , end_reason : VoiceEndReason = VoiceEndReason .NORMAL
548+ ) -> None :
547549 """Cleanup internal state for a voice session.
548550
549551 - Cancel and remove any pending timeout task for the session.
@@ -559,7 +561,7 @@ async def _cleanup_voice_session(self, session_id: int) -> None:
559561 # End and remove session
560562 session = self ._voice_sessions .pop (session_id , None )
561563 if session is not None and not session .closed :
562- session .end () # normal close
564+ session .end (end_reason )
563565
564566 # Remove ownership mappings
565567 try :
@@ -615,8 +617,6 @@ async def _run_voice_handler(self, session: VoiceSession) -> None:
615617 result = handler (session )
616618 if asyncio .iscoroutine (result ):
617619 await result
618- if not session .closed :
619- session .end ()
620620 except Exception as ex : # pylint: disable=W0718
621621 _LOG .exception ("Voice handler failed for session %s" , session .session_id )
622622 if not session .closed :
0 commit comments