lib: fix fs.readdir recursive async#56041
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #56041 +/- ##
========================================
Coverage 88.00% 88.01%
========================================
Files 653 656 +3
Lines 188093 189077 +984
Branches 35942 36006 +64
========================================
+ Hits 165537 166412 +875
- Misses 15734 15840 +106
- Partials 6822 6825 +3
|
| } | ||
| } | ||
|
|
||
| function handleDirents({ result, currentPath, context }) { |
There was a problem hiding this comment.
Would you mind adding jsdoc to all newly/updated functions?
There was a problem hiding this comment.
I haven't added jsdoc to these ones because they are not public, they are used inside readdirRecursive (which has JSDoc). It seems a pattern on this file.
LiviaMedeiros
left a comment
There was a problem hiding this comment.
Line 1533 in 982a50e
If
options gets mutated (for example, to be reused subsequent readdir) after the function call during the directory processing, the results might become unpredictable. We should copyObject() it.
|
CI is failing |
|
Thanks @aduh95. I forgot the readdir tests runs on |
| for (let i = 0; i < context.pathsQueue.length; i++) { | ||
| read(context.pathsQueue[i]); | ||
| } |
There was a problem hiding this comment.
I know this is somewhat out of scope of the PR, I just wondered if we want to limit the amount of reads triggered to an upper bound of available file descriptors? That way we would not allocate anything before it's needed and it would probably reduce memory and increase performance a tad.
There was a problem hiding this comment.
Hmm, that makes sense. But I wouldn't include it on this PR as it just fixes an async behavior. Currently, fs.readdir() - async performs one operation per time:
-> readdir -> cb -> readdir -> cb ...
But at some point, we could read from parallel folders within the same callback, which would improve performance significantly (memory would increase, though).
Commit Queue failed- Loading data for nodejs/node/pull/56041 ✔ Done loading data for nodejs/node/pull/56041 ----------------------------------- PR info ------------------------------------ Title lib: fix fs.readdir recursive async (#56041) Author Rafael Gonzaga <rafael.nunu@hotmail.com> (@RafaelGSS) Branch RafaelGSS:fix-readdir-async-throw -> nodejs:main Labels fs, author ready Commits 3 - lib: fix fs.readdir recursive async - fixup! lib: fix fs.readdir recursive async - fixup! fixup! lib: fix fs.readdir recursive async Committers 1 - RafaelGSS <rafael.nunu@hotmail.com> PR-URL: https://github.com/nodejs/node/pull/56041 Fixes: https://github.com/nodejs/node/issues/56006 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/56041 Fixes: https://github.com/nodejs/node/issues/56006 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last approving review: ⚠ - fixup! fixup! lib: fix fs.readdir recursive async ℹ This PR was created on Wed, 27 Nov 2024 20:05:17 GMT ✔ Approvals: 2 ✔ - Ethan Arrowood (@Ethan-Arrowood): https://github.com/nodejs/node/pull/56041#pullrequestreview-2470295506 ✔ - Juan José Arboleda (@juanarbol): https://github.com/nodejs/node/pull/56041#pullrequestreview-2470693898 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2024-12-04T20:46:30Z: https://ci.nodejs.org/job/node-test-pull-request/63877/ - Querying data for job/node-test-pull-request/63877/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/12172531267 |
|
Could someone re-approve? I pushed 16a29cb after approvals. |
|
Landed in 53356c3 |
Fixes: #56006
cc: @aduh95 @Ethan-Arrowood