@@ -401,10 +401,7 @@ async def disconnect(self) -> None:
401401 if not self .isconnected ():
402402 return
403403
404- if self ._rpc_invocation_tasks :
405- for task in self ._rpc_invocation_tasks :
406- task .cancel ()
407- await asyncio .gather (* self ._rpc_invocation_tasks , return_exceptions = True )
404+ await self ._drain_rpc_invocation_tasks ()
408405
409406 req = proto_ffi .FfiRequest ()
410407 req .disconnect .room_handle = self ._ffi_handle .handle # type: ignore
@@ -443,6 +440,9 @@ async def _listen_task(self) -> None:
443440 self ._room_queue .put_nowait (event )
444441 await self ._room_queue .join ()
445442
443+ # Clean up any pending RPC invocation tasks
444+ await self ._drain_rpc_invocation_tasks ()
445+
446446 def _on_rpc_method_invocation (self , rpc_invocation : RpcMethodInvocationEvent ):
447447 if self ._local_participant is None :
448448 return
@@ -710,6 +710,12 @@ def _on_room_event(self, event: proto_room.RoomEvent):
710710 elif which == "reconnected" :
711711 self .emit ("reconnected" )
712712
713+ async def _drain_rpc_invocation_tasks (self ) -> None :
714+ if self ._rpc_invocation_tasks :
715+ for task in self ._rpc_invocation_tasks :
716+ task .cancel ()
717+ await asyncio .gather (* self ._rpc_invocation_tasks , return_exceptions = True )
718+
713719 def _retrieve_remote_participant (
714720 self , identity : str
715721 ) -> Optional [RemoteParticipant ]:
0 commit comments