-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: fix memory leak for v8.serialize #42695
src: fix memory leak for v8.serialize #42695
Conversation
When Buffer::New passes in existing data, it cannot be garbage collected in js synchronous execution. Fixes: nodejs#40828 Refs: nodejs#38300
24c5304
to
809386a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#40828 (comment) is the right comment here here: This is currently not working because the garbage collector does not get a chance to run, including in the test case here.
This change here is not a good solution. It adds an unnecessary buffer copy without real benefit.
If you do want to fix this in a better way, you’ll need to modify Buffer::New(Environment*,char*,size_t)
to not call into Buffer::New(Environment*,char*,size_t,FreeCallback,void);
instead.
The best way to fix this is to keep reminding users that Buffer
GC may need to perform some cleanup asynchronously, and Buffer
instances may be kept alive until synchronous code stops running.
Thanks for your review!
Although an extra memory copy is added, the test becomes faster, perhaps due to the reduced use of And it takes less memory and is more stable. In some cases, such as
Can you give me more help? I'd love to use this better method! I have tried modifying the And using
But this problem leads to bad performance and even crashes, and there is no good way to avoid it other than changing everything to async. |
The goal here would be to avoid So – the idea here is, instead of using
The really nice thing about this approach would be that it takes care of this problem in all situations in which
I assume that this would depend a bit on how much memory is allocated – longer buffers take longer to copy, but (typically) a constant amount of time to release.
Nice! To be clear, I would absolutely love to see this :) |
Thank you very much for your detailed help, I will try it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you!
It seems that the test is so strict that it fails on jenkins, I changed it from less than 10mb increments to less than double. |
Landed in ce29d28 |
When Buffer::New passes in existing data, it cannot be garbage collected in js synchronous execution. Fixes: #40828 Refs: #38300 PR-URL: #42695 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
When Buffer::New passes in existing data, it cannot be garbage collected in js synchronous execution. Fixes: #40828 Refs: #38300 PR-URL: #42695 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
When Buffer::New passes in existing data, it cannot be garbage collected in js synchronous execution. Fixes: #40828 Refs: #38300 PR-URL: #42695 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
When Buffer::New passes in existing data, it cannot be garbage collected in js synchronous execution. Fixes: #40828 Refs: #38300 PR-URL: #42695 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
When Buffer::New passes in existing data, it cannot be garbage collected in js synchronous execution. Fixes: #40828 Refs: #38300 PR-URL: #42695 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
nodejs/node#42695 This test does not work for Electron as they do not use V8's ArrayBufferAllocator.
nodejs/node#42695 This test does not work for Electron as they do not use V8's ArrayBufferAllocator.
nodejs/node#42695 This test does not work for Electron as they do not use V8's ArrayBufferAllocator.
* chore: bump node in DEPS to v16.17.0 * chore: fixup asar patch * lib: use null-prototype objects for property descriptors nodejs/node#43270 * src: make SecureContext fields private nodejs/node#43173 * crypto: remove Node.js-specific webcrypto extensions nodejs/node#43310 * test: refactor to top-level await nodejs/node#43500 * deps: cherry-pick two libuv fixes nodejs/node#43950 * src: slim down env-inl.h nodejs/node#43745 * util: add AggregateError.prototype.errors to inspect output nodejs/node#43646 * esm: improve performance & tidy tests nodejs/node#43784 * src: NodeArrayBufferAllocator delegates to v8's allocator nodejs/node#43594 * chore: update patch indices * chore: update filenames * src: refactor IsSupportedAuthenticatedMode nodejs/node#42368 * src: add --openssl-legacy-provider option nodejs/node#40478 * lib,src: add source map support for global eval nodejs/node#43428 * trace_events: trace net connect event nodejs/node#43903 * deps: update ICU to 71.1 nodejs/node#42655 This fails the test because it's missing https://chromium-review.googlesource.com/c/chromium/deps/icu/+/3841093 * lib: give names to promisified exists() and question() nodejs/node#43218 * crypto: add CFRG curves to Web Crypto API nodejs/node#42507 * src: fix memory leak for v8.serialize nodejs/node#42695 This test does not work for Electron as they do not use V8's ArrayBufferAllocator. * buffer: fix atob input validation nodejs/node#42539 * src: fix ssize_t error from nghttp2.h nodejs/node#44393 Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <[email protected]>
When Buffer::New passes in existing data, it cannot be garbage collected in js synchronous execution. Fixes: nodejs/node#40828 Refs: nodejs/node#38300 PR-URL: nodejs/node#42695 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
* chore: bump node in DEPS to v16.17.0 * chore: fixup asar patch * lib: use null-prototype objects for property descriptors nodejs/node#43270 * src: make SecureContext fields private nodejs/node#43173 * crypto: remove Node.js-specific webcrypto extensions nodejs/node#43310 * test: refactor to top-level await nodejs/node#43500 * deps: cherry-pick two libuv fixes nodejs/node#43950 * src: slim down env-inl.h nodejs/node#43745 * util: add AggregateError.prototype.errors to inspect output nodejs/node#43646 * esm: improve performance & tidy tests nodejs/node#43784 * src: NodeArrayBufferAllocator delegates to v8's allocator nodejs/node#43594 * chore: update patch indices * chore: update filenames * src: refactor IsSupportedAuthenticatedMode nodejs/node#42368 * src: add --openssl-legacy-provider option nodejs/node#40478 * lib,src: add source map support for global eval nodejs/node#43428 * trace_events: trace net connect event nodejs/node#43903 * deps: update ICU to 71.1 nodejs/node#42655 This fails the test because it's missing https://chromium-review.googlesource.com/c/chromium/deps/icu/+/3841093 * lib: give names to promisified exists() and question() nodejs/node#43218 * crypto: add CFRG curves to Web Crypto API nodejs/node#42507 * src: fix memory leak for v8.serialize nodejs/node#42695 This test does not work for Electron as they do not use V8's ArrayBufferAllocator. * buffer: fix atob input validation nodejs/node#42539 * src: fix ssize_t error from nghttp2.h nodejs/node#44393 Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <[email protected]>
Fixes: #40828
Refs: #38300