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

src: make AliasedBuffers in the binding data weak #47354

Merged
merged 1 commit into from
Apr 20, 2023

Conversation

joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented Apr 1, 2023

src: make AliasedBuffers in the binding data weak

The binding data holds references to the AliasedBuffers directly
from their wrappers which already ensures that the AliasedBuffers
won't be accessed when the wrappers are GC'ed. So we can just
make the global references to the AliasedBuffers weak. This way
we can simply deserialize the typed arrays when deserialize the
binding data and avoid the extra Object::Set() calls. It also
eliminates the caveat in the JS land where aliased buffers must
be dynamically read from the binding.

Refs: #47353

(This doesn't fix #47353, but it makes sense on its own, and at least reduces the number of unnecessary global references...)

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Apr 1, 2023
@joyeecheung joyeecheung force-pushed the aliased-buffer-weak branch 2 times, most recently from 994c28e to 51e1b26 Compare April 1, 2023 20:01
@nodejs nodejs deleted a comment from nodejs-github-bot Apr 1, 2023
@joyeecheung joyeecheung force-pushed the aliased-buffer-weak branch 2 times, most recently from ebc51a9 to fa8189f Compare April 1, 2023 20:11
@nodejs nodejs deleted a comment from nodejs-github-bot Apr 1, 2023
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

src/aliased_buffer-inl.h Show resolved Hide resolved
src/node_v8.cc Outdated Show resolved Hide resolved
The binding data holds references to the AliasedBuffers directly
from their wrappers which already ensures that the AliasedBuffers
won't be accessed when the wrappers are GC'ed. So we can just
make the global references to the AliasedBuffers weak. This way
we can simply deserialize the typed arrays when deserialize the
binding data and avoid the extra Object::Set() calls. It also
eliminates the caveat in the JS land where aliased buffers must
be dynamically read from the binding.
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@jasnell
Copy link
Member

jasnell commented Apr 10, 2023

It's not immediately clear if this will impact the new BindingData and AliasedBuffer uses in src/quic?

@joyeecheung
Copy link
Member Author

joyeecheung commented Apr 10, 2023

It's not immediately clear if this will impact the new BindingData and AliasedBuffer uses in src/quic?

It makes some BindingData included in the default bootstrap weak to at least not leak in shadow realms. For other BindingData it's not strictly necessary but it's a good practice.

@legendecas legendecas added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. labels Apr 13, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 20, 2023
@nodejs-github-bot nodejs-github-bot merged commit b68cedd into nodejs:main Apr 20, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in b68cedd

targos pushed a commit that referenced this pull request May 2, 2023
The binding data holds references to the AliasedBuffers directly
from their wrappers which already ensures that the AliasedBuffers
won't be accessed when the wrappers are GC'ed. So we can just
make the global references to the AliasedBuffers weak. This way
we can simply deserialize the typed arrays when deserialize the
binding data and avoid the extra Object::Set() calls. It also
eliminates the caveat in the JS land where aliased buffers must
be dynamically read from the binding.

PR-URL: #47354
Refs: #47353
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
@targos targos mentioned this pull request May 2, 2023
@danielleadams danielleadams added the backport-requested-v18.x PRs awaiting manual backport to the v18.x-staging branch. label Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backport-requested-v18.x PRs awaiting manual backport to the v18.x-staging branch. c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

memory leak in shadow realms
5 participants