Skip to content
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

lib: fix fs.readdir recursive async #56041

Merged
merged 3 commits into from
Dec 5, 2024

Conversation

RafaelGSS
Copy link
Member

@RafaelGSS RafaelGSS commented Nov 27, 2024

@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Nov 27, 2024
Copy link

codecov bot commented Nov 27, 2024

Codecov Report

Attention: Patch coverage is 92.98246% with 8 lines in your changes missing coverage. Please review.

Project coverage is 88.01%. Comparing base (ce346b6) to head (16a29cb).
Report is 71 commits behind head on main.

Files with missing lines Patch % Lines
lib/fs.js 92.98% 8 Missing ⚠️
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     
Files with missing lines Coverage Δ
lib/fs.js 93.26% <92.98%> (-0.09%) ⬇️

... and 55 files with indirect coverage changes

@RafaelGSS RafaelGSS added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 27, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 27, 2024
@nodejs-github-bot
Copy link
Collaborator

}
}

function handleDirents({ result, currentPath, context }) {
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind adding jsdoc to all newly/updated functions?

Copy link
Member Author

@RafaelGSS RafaelGSS Nov 28, 2024

Choose a reason for hiding this comment

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

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.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

lib/fs.js Outdated Show resolved Hide resolved
Copy link
Contributor

@LiviaMedeiros LiviaMedeiros left a comment

Choose a reason for hiding this comment

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

node/lib/fs.js

Line 1533 in 982a50e

options = getOptions(options);

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.

lib/fs.js Outdated Show resolved Hide resolved
lib/fs.js Outdated Show resolved Hide resolved
lib/fs.js Outdated Show resolved Hide resolved
Copy link
Contributor

@Ethan-Arrowood Ethan-Arrowood left a comment

Choose a reason for hiding this comment

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

lgtm

@aduh95
Copy link
Contributor

aduh95 commented Nov 29, 2024

CI is failing

Path: parallel/test-fs-readdir-types-symlinks
Error: --- stderr ---
node:internal/errors:540
      throw error;
      ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Array
    at Object.join (node:path:1261:7)
    at handleFilePaths (node:fs:1458:35)
    at processReaddirResult (node:fs:1437:93)
    at read (node:fs:1497:5)
    at readdirSyncRecursive (node:fs:1505:5)
    at Object.readdirSync (node:fs:1576:12)
    at Object.<anonymous> (/home/runner/work/node/node/test/parallel/test-fs-readdir-types-symlinks.js:34:6)
    at Module._compile (node:internal/modules/cjs/loader:1566:14)
    at Object..js (node:internal/modules/cjs/loader:1718:10)
    at Module.load (node:internal/modules/cjs/loader:1305:32) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v24.0.0-pre
Command: out/Release/node --test-reporter=spec --test-reporter-destination=stdout --test-reporter=./tools/github_reporter/index.js --test-reporter-destination=stdout /home/runner/work/node/node/test/parallel/test-fs-readdir-types-symlinks.js
=== release test-fs-readdir-recursive ===
Path: sequential/test-fs-readdir-recursive
Error: --- stderr ---
node:internal/errors:540
      throw error;
      ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Array
    at Object.join (node:path:1261:7)
    at handleFilePaths (node:fs:1458:35)
    at processReaddirResult (node:fs:1437:93)
    at read (node:fs:1497:5)
    at readdirSyncRecursive (node:fs:1505:5)
    at Object.readdirSync (node:fs:1576:12)
    at Object.<anonymous> (/home/runner/work/node/node/test/sequential/test-fs-readdir-recursive.js:156:21)
    at Module._compile (node:internal/modules/cjs/loader:1566:14)
    at Object..js (node:internal/modules/cjs/loader:1718:10)
    at Module.load (node:internal/modules/cjs/loader:1305:32) {
  code: 'ERR_INVALID_ARG_TYPE'
}

@RafaelGSS
Copy link
Member Author

Thanks @aduh95. I forgot the readdir tests runs on sequential. I'll check

Copy link
Member

@juanarbol juanarbol left a comment

Choose a reason for hiding this comment

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

sgtm

@RafaelGSS RafaelGSS added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 3, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 3, 2024
@nodejs-github-bot
Copy link
Collaborator

Comment on lines +1503 to 1505
for (let i = 0; i < context.pathsQueue.length; i++) {
read(context.pathsQueue[i]);
}
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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).

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@RafaelGSS RafaelGSS added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 4, 2024
@juanarbol juanarbol added commit-queue Add this label to land a pull request using GitHub Actions. and removed needs-ci PRs that need a full CI run. labels Dec 5, 2024
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Dec 5, 2024
@nodejs-github-bot
Copy link
Collaborator

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 <[email protected]> (@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 <[email protected]>
PR-URL: https://github.com/nodejs/node/pull/56041
Fixes: https://github.com/nodejs/node/issues/56006
Reviewed-By: Ethan Arrowood <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/56041
Fixes: https://github.com/nodejs/node/issues/56006
Reviewed-By: Ethan Arrowood <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
--------------------------------------------------------------------------------
   ⚠  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/.ncu
https://github.com/nodejs/node/actions/runs/12172531267

@juanarbol juanarbol added commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Dec 5, 2024
@RafaelGSS
Copy link
Member Author

RafaelGSS commented Dec 5, 2024

Could someone re-approve? I pushed 16a29cb after approvals.

@aduh95 aduh95 added the needs-ci PRs that need a full CI run. label Dec 5, 2024
@aduh95 aduh95 merged commit 53356c3 into nodejs:main Dec 5, 2024
75 checks passed
@aduh95
Copy link
Contributor

aduh95 commented Dec 5, 2024

Landed in 53356c3

targos pushed a commit that referenced this pull request Dec 6, 2024
Fixes: #56006
PR-URL: #56041
Reviewed-By: Ethan Arrowood <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
aduh95 pushed a commit that referenced this pull request Dec 13, 2024
Fixes: #56006
PR-URL: #56041
Reviewed-By: Ethan Arrowood <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
aduh95 pushed a commit that referenced this pull request Dec 13, 2024
Fixes: #56006
PR-URL: #56041
Reviewed-By: Ethan Arrowood <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
aduh95 pushed a commit that referenced this pull request Dec 13, 2024
Fixes: #56006
PR-URL: #56041
Reviewed-By: Ethan Arrowood <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
aduh95 pushed a commit that referenced this pull request Dec 18, 2024
Fixes: #56006
PR-URL: #56041
Reviewed-By: Ethan Arrowood <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
ruyadorno pushed a commit that referenced this pull request Jan 5, 2025
Fixes: #56006
PR-URL: #56041
Reviewed-By: Ethan Arrowood <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
codebytere added a commit to electron/electron that referenced this pull request Jan 28, 2025
codebytere added a commit to electron/electron that referenced this pull request Jan 28, 2025
codebytere added a commit to electron/electron that referenced this pull request Jan 28, 2025
jkleinsc pushed a commit to electron/electron that referenced this pull request Jan 29, 2025
* chore: bump node in DEPS to v22.13.1

* chore: fixup GN build file

* nodejs/node#55529
* nodejs/node#55798
* nodejs/node#55530

* module: simplify --inspect-brk handling

nodejs/node#55679

* src: fix outdated js2c.cc references

nodejs/node#56133

* crypto: include openssl/rand.h explicitly

nodejs/node#55425

* build: use variable for crypto dep path

nodejs/node#55928

* crypto: fix RSA_PKCS1_PADDING error message

nodejs/node#55629

* build: use variable for simdutf path

nodejs/node#56196

* test,crypto: make crypto tests work with BoringSSL

nodejs/node#55491

* fix: suppress clang -Wdeprecated-declarations in libuv

libuv/libuv#4486

* deps: update libuv to 1.49.1

nodejs/node#55114

* test: make test-node-output-v8-warning more flexible

nodejs/node#55401

* [v22.x] Revert "v8: enable maglev on supported architectures"

nodejs/node#54384

* fix: potential WIN32_LEAN_AND_MEAN redefinition

c-ares/c-ares#869

* deps: update nghttp2 to 1.64.0

nodejs/node#55559

* src: provide workaround for container-overflow

nodejs/node#55591

* build: use variable for simdutf path

nodejs/node#56196

* chore: fixup patch indices

* fixup! module: simplify --inspect-brk handling

* lib: fix fs.readdir recursive async

nodejs/node#56041

* lib: avoid excluding symlinks in recursive fs.readdir with filetypes

nodejs/node#55714

This doesn't currently play well with ASAR - this should be fixed in a follow up

* test: disable CJS permission test for config.main

This has diverged as a result of our revert of
src,lb: reducing C++ calls of esm legacy main resolve

* fixup! lib: fix fs.readdir recursive async

* deps: update libuv to 1.49.1

nodejs/node#55114

---------

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fs.readdir(path, { recursive: true }) is sync
10 participants