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

fs: readDir {withFileTypes: true} could call callback more than once #22778

Closed
ajafff opened this issue Sep 9, 2018 · 0 comments
Closed

fs: readDir {withFileTypes: true} could call callback more than once #22778

ajafff opened this issue Sep 9, 2018 · 0 comments
Labels
fs Issues and PRs related to the fs subsystem / file system.

Comments

@ajafff
Copy link
Contributor

ajafff commented Sep 9, 2018

  • Version: 10.10.0
  • Platform:
  • Subsystem: fs

While looking through the code of readDir's new option withFileTypes I noticed that getDirents unconditionally calls the callback in case of an error:

if (err) {
callback(err);
return;
}

If more than one file is of type UV_DIRENT_UNKNOWN and fs.stat returns with an error for more than one of these files, the callback will be called more than once. That could lead to unexpected behavior for API users.

I don't know if that needs to be fixed as the scenario seems very unlikely, but I thought I should at least report it.

@addaleax addaleax added the fs Issues and PRs related to the fs subsystem / file system. label Sep 11, 2018
@danbev danbev closed this as completed in 466cda0 Sep 13, 2018
targos pushed a commit that referenced this issue Sep 15, 2018
This commit ensures that the readdir() callback can only be
called once when the withFileTypes parameter is supplied.

PR-URL: #22793
Fixes: #22778
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
targos pushed a commit that referenced this issue Sep 19, 2018
This commit ensures that the readdir() callback can only be
called once when the withFileTypes parameter is supplied.

PR-URL: #22793
Fixes: #22778
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
targos pushed a commit that referenced this issue Sep 20, 2018
This commit ensures that the readdir() callback can only be
called once when the withFileTypes parameter is supplied.

PR-URL: #22793
Fixes: #22778
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

No branches or pull requests

2 participants