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

emptyDir callback firing twice on EPERM error #392

Closed
kueckermann opened this issue Mar 16, 2017 · 13 comments
Closed

emptyDir callback firing twice on EPERM error #392

kueckermann opened this issue Mar 16, 2017 · 13 comments

Comments

@kueckermann
Copy link

kueckermann commented Mar 16, 2017

The callback is firing twice on my computer when the folder supplied cannot be removed because it is currently accessed by another program.

fs.emptyDir(`${directory}/public/cache`, function(error){
    console.log('Callback')
});

I have no problem if I use fs.emptyDirSync.
I was running version 2.1.1 of fs-extra.

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 16, 2017

@kueckermann Does the callback call with the exact same error both times?

Can't see how this could happen in the code, but it wouldn't hurt to port the internals to promises to make sure this doesn't happen. @manidlou do you want to do this?

@kueckermann
Copy link
Author

kueckermann commented Mar 16, 2017

@RyanZim Looks like they are both EPERM but different functions (unlink and lstat).
Since this function is running on many directories I am logging the directory I am trying to empty and then the error if it exsists otherwise "No Error". I have shortened the file paths to make it clearer.

...
...\nodes\user_frontend_social_login,   No Error
...\nodes\user_frontend_user,           No Error
...\nodes\user_frontend_explore,        EPERM: operation not permitted, unlink '...\cache\en-US'
...\nodes\user_frontend_explore,        EPERM: operation not permitted, lstat '...\cache\en-US'

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 16, 2017

OK, this one is going to take a little digging.

Given that this error originates from unlink and lstat calls, it must be a bug in the remove module (which emptyDir uses under the hood); emptyDir itself doesn't call unlink or lstat.

Could you post the stack traces for both errors?

@manidlou
Copy link
Collaborator

@manidlou do you want to do this?

Sure thing.

it must be a bug in the remove module (which emptyDir uses under the hood); emptyDir itself doesn't call unlink or lstat.

Agreed.

@kueckermann
Copy link
Author

kueckermann commented Mar 16, 2017

@RyanZim Here is the stack, not much there but maybe something you are looking for.

Error: EPERM: operation not permitted, unlink '...\cache\en-US'
    at Error (native)
Error: EPERM: operation not permitted, lstat '...\cache\en-US'
    at Error (native)

Again, I just shortened the file paths to lessen the text.

@manidlou
Copy link
Collaborator

@kueckermann would you please tell us what OS system and node version you are using?

@kueckermann
Copy link
Author

@manidlou I am on Windows 10, version 1607.
Node version 6.9.5

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 16, 2017

Ugh, probably a Windows-only bug.

@manidlou Don't bother with what I said about promises earlier, since the bug is in remove, that doesn't need done.

@manidlou
Copy link
Collaborator

@manidlou Don't bother with what I said about promises earlier, since the bug is in remove, that doesn't need done. 👍

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 16, 2017

@kueckermann I've got an idea. Try this:

Edit the file node_modules/fs-extra/lib/remove/rimraf.js. On line 86, it says fixWinEPERM(p, options, er, cb). Change that line to read return fixWinEPERM(p, options, er, cb). Then try to reproduce this issue and report back. Thanks!

@kueckermann
Copy link
Author

@RyanZim I added return fixWinEPERM(p, options, er, cb) and this solved the issue! Good job.

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 16, 2017

OK, that needs to be fixed in our codebase. Also, that patch needs to be forwarded to rimraf, since this bug also probably exists there too. (fs-extra's remove is a customized version of rimraf.)

I'll try to get this done.

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 16, 2017

Fixed in v2.1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants