Skip to content

src: make AliasedBuffers in the binding data weak - #47354

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
joyeecheung:aliased-buffer-weak
Apr 20, 2023
Merged

src: make AliasedBuffers in the binding data weak#47354
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
joyeecheung:aliased-buffer-weak

Conversation

@joyeecheung

@joyeecheungjoyeecheung commented Apr 1, 2023

Copy link
Copy Markdown
Member

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-botnodejs-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
joyeecheungforce-pushed the aliased-buffer-weak branch 2 times, most recently from 994c28e to 51e1b26CompareApril 1, 2023 20:01
@nodejsnodejs deleted a comment from nodejs-github-botApr 1, 2023
@joyeecheung
joyeecheungforce-pushed the aliased-buffer-weak branch 2 times, most recently from ebc51a9 to fa8189fCompareApril 1, 2023 20:11
@nodejsnodejs deleted a comment from nodejs-github-botApr 1, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@legendecaslegendecas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the fix!

Comment threadsrc/aliased_buffer-inl.h Outdated
Comment threadsrc/node_v8.cc Outdated
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
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@jasnell

Copy link
Copy Markdown
Member

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

@joyeecheung

joyeecheung commented Apr 10, 2023

Copy link
Copy Markdown
MemberAuthor

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.

@legendecaslegendecas 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-botnodejs-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:mainApr 20, 2023
@nodejs-github-bot

Copy link
Copy Markdown
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>
@targostargos mentioned this pull request May 2, 2023
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.c++Issues and PRs that require attention from people who are familiar with C++.lib / srcIssues and PRs related to general changes in the lib or src directory.needs-ciPRs 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

@joyeecheung@nodejs-github-bot@jasnell@legendecas@danielleadams