Skip to content
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

Merged

Conversation

typester
Copy link
Member

@typester typester commented Jan 3, 2025

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)

Copy link
Contributor

ilo-nanpa bot commented Jan 3, 2025

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 .nanpa/<unique-name>.kdl:

minor type="added" "Introduce frobnication algorithm"

refer to the manpage for more information.

Comment on lines 273 to 274
// Store an empty handle for the FFI client that assumes a handle exists for this id.
server.store_handle(handle, vec![].into_boxed_slice());
Copy link
Member Author

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.

Copy link
Member

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 () {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me try it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theomonnom Fixed in d867bee

@typester typester requested review from bcherry and theomonnom January 3, 2025 03:27
@typester typester merged commit 32a582c into main Jan 6, 2025
5 checks passed
@typester typester deleted the typester/free-associated-stream-handles-when-room-is-closed branch January 6, 2025 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants