-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
readdirSync returns deleted folder #4760
Comments
Do you have a virus scanner or other software installed that hooks system calls? |
No, just Windows 10 with default Windows Defender. Turning it off doesn't affect the result. |
Do you need to open the directory in Windows Explorer to get this result ? |
Yes, but it can be any other file manager. |
Is the file deleted when you close the file manager? If yes, then it's the file manager that keeps the file alive. Not much node can do about that. |
The file is deleted immediately after calling the rmdirSync. Most of the file managers (including Windows Explorer) watch the file system changes. If they find the current folder deleted they go up to the parent folder. It's a common behavior and it's the same as in my case - the file manager goes up to app folder. If you run Command prompt and go to the view folder before running the script, you get the exception:
So, if something is holding/locking the folder, you get an exception. If not, shouldn't it wait for the file system since the method is synchronous? (the Sync postfix in the name rmdirSync) |
/cc @nodejs/platform-windows |
try to use
I can not reproduce it if I use |
I can reproduce it on Windows 10. It's not a bug in Node or libuv, these are correctly returning the current state of the filesystem. It's a race condition that's just part of working with a filesystem on Windows. Filesystems don't always provide much guarantees as to order and timing of filesystem operations etc. and the user needs to be aware of this. I think this is what's happening, but I might be wrong:
If it's critical for the user to enforce order, persistence etc. then they should just call |
Also, one needs to run the above test in a script, not a repl, so that the readdir call is made as soon after the rmdir call as possible. Even pasting into the repl does not reproduce it. |
I see that in the same way as @jorangreef. NodeJs documentation says the method fsyncSync has an argument called fd, nothing more. So I guess the fd is a file descriptor. How can I get the file descriptor of the folder that is going to be deleted by rmdirSync to pass it later to fsyncSync to wait for releasing all the handles? Does the fsyncSync method actually wait for releasing all the handles of the folder or it just produces 1 ms time loss which causes returning expected result? |
@pavelzaruba I think you're right. In this case maybe |
Probably not. The folder descriptor passed to fsyncSync...
...throws the exception:
|
I propose to close this due to reasons outlined by @jorangreef. We can't really fix it in Node.js. |
Agreed. |
Hi All, I have reproduced the same steps and I am getting the expected result as "[ [ 'view' ], undefined, [] ]" in both Windows and MacOS. Please let me know, is this defect fixed in node? Thank you |
The function readdirSync returns folder that was already deleted.
steps to reproduce:
expected result:
actual result:
The text was updated successfully, but these errors were encountered: