| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Once an `FSReqCallback` instance is created, it is a GC root until the underlying fs operation has completed, meaning that it cannot be garbage collected. This is a problem when the underlying operation never starts because an exception is thrown before that happens, for example as part of parameter validation. Instead, move all potentially throwing code before the `FSReqCallback` creation.
Sorry, something went wrong.
When a process exits cleanly, i.e. because the event loop ends up
without things to wait for, the Node.js objects that are left on
the heap should be:
1. weak, i.e. ready for garbage collection once no longer
referenced, or
2. detached, i.e. scheduled for destruction once no longer
referenced, or
3. an unrefed libuv handle, i.e. does not keep the event loop
alive, or
4. an inactive libuv handle (essentially the same here)
There are a few exceptions to this rule, but generally,
if there are C++-backed Node.js objects on the heap
that do not fall into the above categories, we may be looking
at a potential memory leak. Most likely, the cause is a missing
`MakeWeak()` call on the corresponding object.
In order to avoid this kind of problem, we check the list
of BaseObjects for these criteria. In this commit, we only do so
when explicitly instructed to or when in debug mode
(where --verify-base-objects is always-on).
In particular, this avoids the kinds of memory leak issues
that were fixed in the PRs referenced below.
Refs: nodejs#35488
Refs: nodejs#35487
Refs: nodejs#35481
Sorry, something went wrong.
There was a problem hiding this comment.
Can we document this somehow? Otherwise next time someone may add a new method that does this again and we would have to catch it through code reviews
Sorry, something went wrong.
|
@joyeecheung I don’t really know where to document this, but #35490 would make CI fail if this happens again, so I think we’re okay there |
Sorry, something went wrong.
Sorry, something went wrong.
|
@addaleax Maybe at the top of the file? (I think when someone tries to add a new method they would probably look there). I imagine when the CI fails they would just see the callback being printed before exit which could be difficult for new comers to understand.. |
Sorry, something went wrong.
|
@joyeecheung I’ve added a comment. |
Sorry, something went wrong.
Sorry, something went wrong.
Commit Queue failed- Loading data for nodejs/node/pull/35487 ✔ Done loading data for nodejs/node/pull/35487 ----------------------------------- PR info ------------------------------------ Title fs: do not throw exception after creating FSReqCallback (#35487) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch addaleax:fsreqcallback -> nodejs:master Labels fs, lts-watch-v12.x Commits 2 - fs: do not throw exception after creating FSReqCallback - fixup! fs: do not throw exception after creating FSReqCallback Committers 1 - Anna Henningsen PR-URL: https://github.com/nodejs/node/pull/35487 Reviewed-By: James M Snell Reviewed-By: Joyee Cheung ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/35487 Reviewed-By: James M Snell Reviewed-By: Joyee Cheung -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last review: ⚠ - fixup! fs: do not throw exception after creating FSReqCallback ✔ Last GitHub Actions successful ℹ Last Full PR CI on 2020-10-05T20:23:13Z: https://ci.nodejs.org/job/node-test-pull-request/33410/ - Querying data for job/node-test-pull-request/33410/ ✔ Build data downloaded ✔ Last Jenkins CI successful ℹ This PR was created on Sat, 03 Oct 2020 22:43:13 GMT ✔ Approvals: 2 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/35487#pullrequestreview-501578948 ✔ - Joyee Cheung (@joyeecheung) (TSC): https://github.com/nodejs/node/pull/35487#pullrequestreview-501630754 -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncu |
Sorry, something went wrong.
Once an `FSReqCallback` instance is created, it is a GC root until the underlying fs operation has completed, meaning that it cannot be garbage collected. This is a problem when the underlying operation never starts because an exception is thrown before that happens, for example as part of parameter validation. Instead, move all potentially throwing code before the `FSReqCallback` creation. PR-URL: #35487 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
| Back | FazBrowse Home | New Git URL |
Once an FSReqCallback instance is created, it is a GC root until
the underlying fs operation has completed, meaning that it cannot
be garbage collected.
This is a problem when the underlying operation never starts
because an exception is thrown before that happens, for example
as part of parameter validation.
Instead, move all potentially throwing code before the FSReqCallback
creation.
Checklist