-
Notifications
You must be signed in to change notification settings - Fork 31.3k
Free req.file.pathw in fs::ReadFileUtf8(). #57811
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
Conversation
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.
lgtm
bc9df87
to
25bb174
Compare
I updated the commit comments after the first CI failure with module names in the title. I think it was mistaking some variable names as modules? I moved the original title into the description. Will that description also get flagged. Is there a safe way to format the variable name without triggering the module name CI check? |
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.
@Justin-Nietzel You need to force-push to your branch issue-57800
with an amended commit message. Since req.file.pathw
is an implementation detail in an external dependency, I'd suggest a commit message title such as fs: add missing call to uv_fs_req_cleanup
or something like that.
Is it safe to also unconditionally call us_fs_req_cleanup(&req)
in defer_close
? It seems very odd to me that defer_close
will always call uv_fs_req_cleanup(&req)
while conditionally reusing &req
for uv_fs_close
. Before #49691, there was a seperate uv_fs_t
for the close operation (cc @anonrig).
Always call uv_fs_req_cleanup after calling uv_fs_open instead of just when uv_fs_open returns a negative result. I referenced ReadFileSync from node:js2c when making this change. https://github.com/bnoordhuis made the same suggestion based on the PR nodejs#49691. Fixes: nodejs#57800
ReadFileSync in js2c.cc follows a very similar workflow to ReadFileUTF8 when using opening a file by file path. It re-uses the |
25bb174
to
a00fc51
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #57811 +/- ##
==========================================
- Coverage 90.23% 90.23% -0.01%
==========================================
Files 630 630
Lines 185465 185471 +6
Branches 36368 36374 +6
==========================================
- Hits 167362 167353 -9
+ Misses 10999 10996 -3
- Partials 7104 7122 +18
🚀 New features to boost your workflow:
|
@Justin-Nietzel do you think you'd be able to add a test that verify the memory leak is fixed? |
I probably could add a unit test. I would reference the readFileSync test and this worker thread memory test. I just had a few questions.
|
Added a unit test for testing the memory usage of readFileSync. Test is looking specifically for the the issue caused by failing to free the filepath buffer in fs::ReadFileUtf8(), but it will also catch other significant memory leaks in readFileSync() as well. Refs: nodejs#57800
@mcollina I added a unit test for this fix and did my best to follow all the documentation I could find on style and testing. Let me know if you need me to make any adjustments. |
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.
lgtm
Always call uv_fs_req_cleanup after calling uv_fs_open instead of just when uv_fs_open returns a negative result. I referenced ReadFileSync from node:js2c when making this change. https://github.com/bnoordhuis made the same suggestion based on the PR #49691. Fixes: #57800 PR-URL: #57811 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
Added a unit test for testing the memory usage of readFileSync. Test is looking specifically for the the issue caused by failing to free the filepath buffer in fs::ReadFileUtf8(), but it will also catch other significant memory leaks in readFileSync() as well. Refs: #57800 PR-URL: #57811 Fixes: #57800 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
Landed in d0a5bd6...09ecd2e |
On a side note for future PRs, the second commit technically does not satisfy our requirements for commit messages since the leading verb is not imperative ( |
Always call uv_fs_req_cleanup after calling uv_fs_open instead of just when uv_fs_open returns a negative result. I referenced ReadFileSync from node:js2c when making this change.
https://github.com/bnoordhuis made the same suggestion based on the PR #49691.
Fixes: #57800