Skip to content

chore: fix memory leak in v8.serialize()#37021

Merged
zcbenz merged 1 commit intomainfrom
fix-memory-leak-serialize
Jan 26, 2023
Merged

chore: fix memory leak in v8.serialize()#37021
zcbenz merged 1 commit intomainfrom
fix-memory-leak-serialize

Conversation

@codebytere
Copy link
Member

@codebytere codebytere commented Jan 25, 2023

Description of Change

Refs nodejs/node@74a5956

Fixes a memory leak in v8.serialize() resultant of gc not being able to run properly. I implemented a modified version of this approach to be compatible with sandboxed pointers.

Result of parallel/test-v8-serialize-leak:
Before this change:

  • before=85573632 after=4512022528 - 52.7x increased memory usage

After this change

  • before=85524480 after=189775872 - 2.2x increased memory usage

Checklist

Release Notes

Notes: Fixed a memory leak in v8.serialize() when running Node.js within Electron.

@codebytere codebytere added semver/patch backwards-compatible bug fixes target/22-x-y PR should also be added to the "22-x-y" branch. target/23-x-y PR should also be added to the "23-x-y" branch. labels Jan 25, 2023
@codebytere codebytere requested a review from nornagon January 25, 2023 14:59
@codebytere codebytere requested a review from a team as a code owner January 25, 2023 14:59
@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Jan 25, 2023
Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

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

The ArrayBuffer::New(..., NewBackingStore()) -> Node Buffer::New() sequence here makes sense to me and is consistent with the change that got merged upstream in 42695.

@codebytere thanks for linking to Anna's informative writeup of why this sequence is preferable and how it avoids the GC issue. 👍

@zcbenz zcbenz merged commit c6b9340 into main Jan 26, 2023
@zcbenz zcbenz deleted the fix-memory-leak-serialize branch January 26, 2023 06:43
@release-clerk
Copy link

release-clerk bot commented Jan 26, 2023

Release Notes Persisted

Fixed a memory leak in v8.serialize() when running Node.js within Electron.

@trop
Copy link
Contributor

trop bot commented Jan 26, 2023

I was unable to backport this PR to "22-x-y" cleanly;
you will need to perform this backport manually.

@trop trop bot added needs-manual-bp/22-x-y and removed target/22-x-y PR should also be added to the "22-x-y" branch. labels Jan 26, 2023
@trop
Copy link
Contributor

trop bot commented Jan 26, 2023

I have automatically backported this PR to "23-x-y", please check out #37030

@trop trop bot added in-flight/23-x-y merged/23-x-y PR was merged to the "23-x-y" branch. and removed target/23-x-y PR should also be added to the "23-x-y" branch. in-flight/23-x-y labels Jan 26, 2023
khalwa pushed a commit to solarwindscloud/electron that referenced this pull request Feb 22, 2023
chore: fix memory leak in v8.serialize()
gecko19 pushed a commit to brightsign/electron that referenced this pull request Feb 28, 2023
chore: fix memory leak in v8.serialize()
@trop
Copy link
Contributor

trop bot commented Mar 31, 2023

@yehengxuan has manually backported this PR to "22-x-y", please check out #37774

@trop trop bot added the merged/22-x-y PR was merged to the "22-x-y" branch. label Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/22-x-y PR was merged to the "22-x-y" branch. merged/23-x-y PR was merged to the "23-x-y" branch. new-pr 🌱 PR opened recently semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants