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

fix(Buffer): prevent memory leak when Custom GC is used #1963

Merged
merged 1 commit into from Feb 20, 2024

Conversation

lbarthon
Copy link
Contributor

There is a piece of custom logic that has been added a while back to ensure that Buffers can be sent across threads, and be dropped properly. This involves a custom GC that runs on NodeJS's current thread (per my understanding). The logic to drop the buffer on that custom GC differed from the one in the Drop impl. This meant that everytime Node sent a buffer back to a napi-rs function, the reference wouldn't be cleaned up properly, and it would leak (96 bytes per Reference on an ARM MacOS machine).

This commit updates the logic in the custom GC so that it matches the one in the Drop impl. This worked locally, and fixed any occurence of the leak I could find.

There is a piece of custom logic that has been added a while back to ensure
that Buffers can be sent across threads, and be dropped properly. This involves
a custom GC that runs on NodeJS's current thread (per my understanding). The
logic to drop the buffer on that custom GC differed from the one in the Drop
impl. This meant that everytime Node sent a buffer back to a napi-rs function,
the reference wouldn't be cleaned up properly, and it would leak (96 bytes per
Reference on an ARM MacOS machine).

This commit updates the logic in the custom GC so that it matches the one in
the Drop impl. This worked locally, and fixed any occurence of the leak I could
find.
@lbarthon lbarthon force-pushed the lbarthon/buffer-customgc-leak branch from 9a2845d to a806675 Compare February 20, 2024 09:16
@Brooooooklyn Brooooooklyn merged commit 9391196 into napi-rs:main Feb 20, 2024
41 of 42 checks passed
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.

None yet

2 participants