@@ -202,7 +202,16 @@ async def sid(self) -> str:
202202 if self ._info .sid :
203203 return self ._info .sid
204204
205- return await self ._first_sid_future
205+ # This future is shared state for the Room. Caller-side timeouts, e.g.
206+ # asyncio.wait_for(room.sid, ...), should not cancel it for future waiters.
207+ return await asyncio .shield (self ._first_sid_future )
208+
209+ def _resolve_first_sid (self , sid : str ) -> None :
210+ # The room SID can arrive through the initial connect result or later
211+ # room update events. Resolve the first-SID waiter from any source that
212+ # carries it so waiters do not depend on event ordering.
213+ if sid and not self ._first_sid_future .done ():
214+ self ._first_sid_future .set_result (sid )
206215
207216 @property
208217 def local_participant (self ) -> LocalParticipant :
@@ -545,6 +554,7 @@ def on_participant_connected(participant):
545554 )
546555
547556 self ._info = cb .connect .result .room .info
557+ self ._resolve_first_sid (self ._info .sid )
548558 self ._connection_state = ConnectionState .CONN_CONNECTED
549559
550560 self ._local_participant = LocalParticipant (
@@ -859,8 +869,7 @@ def _on_room_event(self, event: proto_room.RoomEvent) -> None:
859869 self ._info .metadata = event .room_metadata_changed .metadata
860870 self .emit ("room_metadata_changed" , old_metadata , self .metadata )
861871 elif which == "room_sid_changed" :
862- if not self ._info .sid :
863- self ._first_sid_future .set_result (event .room_sid_changed .sid )
872+ self ._resolve_first_sid (event .room_sid_changed .sid )
864873 self ._info .sid = event .room_sid_changed .sid
865874 # This is an internal event, not exposed to users
866875 elif which == "participant_metadata_changed" :
@@ -1019,10 +1028,12 @@ def _on_room_event(self, event: proto_room.RoomEvent) -> None:
10191028
10201029 elif which == "room_updated" :
10211030 self ._info = event .room_updated
1031+ self ._resolve_first_sid (self ._info .sid )
10221032 self .emit ("room_updated" )
10231033
10241034 elif which == "moved" :
10251035 self ._info = event .moved
1036+ self ._resolve_first_sid (self ._info .sid )
10261037 self .emit ("moved" )
10271038
10281039 elif which == "participants_updated" :
0 commit comments