Repository navigation
Conversation
Room.disconnect() is the only place that removed onFfiEvent from the FfiClient, and it returns early when the room is no longer connected. A room disconnected by the server (room deleted, participant removed, room closed) therefore kept its listener for the life of the process: every later FFI event of any room reached it, and the closure kept the Room from being garbage collected. cleanupOnDisconnect(), which both disconnect paths run, now removes the listener.
disconnect() still removed onFfiEvent after its callback. When the FFI room event wins the race, cleanupOnDisconnect() has already removed it and emitted RoomEvent.Disconnected; a connect() started from that event registers the listener again, and the trailing removal then took it away from the new connection. cleanupOnDisconnect() now owns the removal, and a test covers a connect() started from RoomEvent.Disconnected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Room.disconnect()is the only place that removes the room'sonFfiEventlistener from theFfiClient, and it returns early once the room is no longer connected. When the server ends the connection (the room is deleted withRoomServiceClient.deleteRoom, the participant is removed, the room closes), the FFIdisconnectedevent runscleanupOnDisconnect()andRoomEvent.Disconnectedfires, but the listener stays on theFfiClientsingleton for the life of the process. Callingroom.disconnect()afterwards does not remove it either, since the room is already disconnected.In a long-running process that joins many rooms and is disconnected by the server when each one ends (a server-side participant or agent, for example):
ffiEventLockbefore discarding the event, so the cost of each event grows with the number of rooms ever disconnected server-side;Roomobjects, with their participants and publications, from being garbage collected;connect()again on such aRoomregistersonFfiEventa second time.Reproduction
Against a local LiveKit server: three rounds of 50 rooms, each joined by one
Roomand then deleted withRoomServiceClient.deleteRoom, waiting forRoomEvent.Disconnectedeach time.ffi_eventlisteners after round 1 / 2 / 3@livekit/rtc-node1.2.3Script
Change
cleanupOnDisconnect(), which both the explicit and the server-initiated path run once per connection, now removesonFfiEventfrom theFfiClient, before it emitsRoomEvent.Disconnected. The removal thatdisconnect()did after its callback is gone: when the FFI room event arrives first and aconnect()is started fromRoomEvent.Disconnected, that trailing removal would take the listener away from the new connection.Tests
New unit tests in
room.test.ts, on theffi_eventregistrations of a room:disconnectedroom event; fails onmain);disconnect();connect()started fromRoomEvent.Disconnectedwhiledisconnect()waits for its callback (passes onmain, and would fail ifdisconnect()still removed the listener).vitest run src(the e2e suites excluded) passes,pnpm lintreports no new warnings, and the reproduction above was rerun on the final version.@livekit/rtc-node.