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

[Win] Deleting folder results in EPERM error that locks all folders that are recursively watched #643

Closed
Faline10 opened this issue Oct 14, 2017 · 5 comments

Comments

@Faline10
Copy link

Faline10 commented Oct 14, 2017

The Issue:
[Windows only] Chokidar (and fs.watch under the hood) throws an EPERM error when a child folder of a folder that is being watched recursively is deleted.
According to notes i saw on another bug, the Chokidar code here is supposed to deal with it:

watcher.on('error', function(error) {
// Workaround for https://github.com/joyent/node/issues/4337
if (process.platform === 'win32' && error.code === 'EPERM') {
fs.open(path, 'r', function(err, fd) {
if (fd) fs.close(fd);
if (!err) broadcastErr(error);
});
} else {
broadcastErr(error);
}
});

In fact, the comments even lead to this old underlying bug in node:
nodejs/node-v0.x-archive#4337 "Deleting a watched folder in Windows ALWAYS rise an [Error: watch EPERM]"
I'm not sure what these lines are supposed to do to address this bug though. It seems to be just broadcasting the error, as long as the file exists.

Now it would be one thing if I could ignore this error and everything would continue to work. In fact, the watchers do continue to work, receiving the unlinkDir event and others. However, a recursive watcher will then lock all child folders, and any file system operation (delete, rename, etc) on them will fail due to EPERM, whether the operation is through node or the windows file system GUI. This issue doesn't seem to occur with non-recursive watchers, perhaps because the underlying node issue is to throw that error for the top level folder being watched. I'm not sure if Chokidar is creating many watchers for child folders under the hood, but if it is, that would make sense with this old bug.

Turning on the option to suppress EPERM errors from within Chokidar does not stop it from locking up afterwards.

Shutting down the watcher after the EPERM error gets rid of the lock. However, restarting causes it to come back(!).

It doesn't seem to be possible to stop the EPERM error from occurring in the first place using Chokidar or fs.watch, as far as I know. Though perhaps NSFW would be an alternative library that doesn't rely on fs.watch.

Device:
Windows 10 Pro, 64bit

Example code:

const watcher = chokidar.watch(path, {
  persistent: true,
  ignoreInitial: true,
  cwd: path
});

// insert business logic on events

watcher.on('error', error => {
  logger.log(error)
  if (error.code === 'EPERM' && Config.WINDOWS) {
    // recursive watcher causes a lock on all watched folders on Windows after EPERM error, so could close it here
    // ...but restarting it causes the locking issue to come back, so that's not the solution
  }
});

I'm aware that the EPERM fs.watch errors are out of Chokidar's hands. However, I'm surprised that the resulting locking issue occurs. Any thoughts on solutions or, for the meantime, workarounds for the locking issue?

@Faline10 Faline10 changed the title EPERM error when deleting folders [Windows], then locks folders that are recursively watched [Win] EPERM error when deleting folders, then locks folders that are recursively watched Oct 14, 2017
@Faline10 Faline10 changed the title [Win] EPERM error when deleting folders, then locks folders that are recursively watched [Win] Deleting folder results in EPERM error that locks all folders that are recursively watched Oct 16, 2017
@Faline10
Copy link
Author

Update: We switched from using Chokidar to Node Sentinel File Watcher (https://www.gitkraken.com/nsfw). As a native library, it avoids Windows EPERM errors and the locking issues that resulted. I'm not closing this bug, though, since this is still a major issue with Chokidar.

@sant123
Copy link

sant123 commented Nov 23, 2017

See #566 (comment)

@paulmillr
Copy link
Owner

Update to Chokidar v3, it should resolve this.

@iniatse
Copy link

iniatse commented Aug 16, 2019

it is not solved in v3...

@paulmillr
Copy link
Owner

Let's move to #566

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

No branches or pull requests

4 participants