-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Close track FFI handles automatically when a FfiRoom is closed. #539
Close track FFI handles automatically when a FfiRoom is closed. #539
Conversation
it seems like you haven't added any nanpa changeset files to this PR. if this pull request includes changes to code, make sure to add a changeset, by writing a file to
refer to the manpage for more information. |
livekit-ffi/src/server/room.rs
Outdated
// Store an empty handle for the FFI client that assumes a handle exists for this id. | ||
server.store_handle(handle, vec![].into_boxed_slice()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Python-side code assumes this handle ID exists, and if the ID does not exist when Python attempts to dispose of it, an assertion failure occurs. To avoid this, an empty entry is stored here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we implement FfiHandle for ()?
impl FfiHandle for () {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me try it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@theomonnom Fixed in d867bee
As shown in this test script, it seems that if the FFI client forgets to close Audio/Video Stream on their side, a memory leak occurs.
Looking at the Python-side code, the
__del__
method is supposed to dispose of FFI handles when objects like VideoStream are released. However, for some reason, in this test script, that part is not invoked, leaving the handles unclosed.In this pull request, the
FfiRoom
is modified to automatically dispose of associated track handles when it is closed.With the script mentioned above, after running it, the memory consumption of the test process decreased from around 110MB to about 80MB, indicating the change is effective.
(The test was conducted in a local environment using a livekit-server with one video and one audio stream are running in a joined room)