Description
Affected URL(s)
https://nodejs.org/api/fs.html#fspromisesreaddirpath-options
Description of the problem
The readdir
method specifies a recursive
option that "reads the contents of a directory recursively". This can be a potentially expensive/long-running filesystem query.
The current implementation is synchronous (see below), which means that passing recursive:true
would block the calling thread until the I/O completes. Ideally, the implementation would not block the calling thread, but until that is implemented (I didn't find any open issue), the least that can be done is to update the documentation to warn about this risk.
Another aspect worth documenting is to explicitly call out that symlinks are NOT followed. If symlinks were to be followed, then that could potentially result in security issues, such as DoS (infinite readdir loop) or directory traversal outside of the specified directory.
Relevant issues / PRs that introduced this feature:
- Recursively list file paths in directory #34992
- fs: add recursive opendir/readdir #41439
- Recursive readdir tooling#130
Relevant source:
Lines 1458 to 1467 in 544cfc5