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
Potential resource leak in unwatch() - seen in getWatched() #1275
Comments
Right. I think removing glob support altogether will solve this if v4 is released. |
If I understand correctly, this means that a fix will only be available in v4, correct? I am running this with |
I don't focus much on Chokidar these days, so unless someone contributes a fix, yes. |
Thank you for clarifying. At the moment, I am using the following workaround, but I may take a stab at it if I get the bandwidth. I am not sure what are the drawbacks of my approach or whether any resources leak. const chokidar = require('chokidar');
function newFSWatcher() {
return new chokidar.FSWatcher({}).on('all', (event, path) => {
console.log(event, path);
});
}
let watcher = newFSWatcher()
let WATCHED_PATH = null
async function changePath(path) {
if (WATCHED_PATH) {
await watcher.close()
watcher = newFSWatcher()
}
WATCHED_PATH = path
watcher.add(WATCHED_PATH)
}
setTimeout(() => changePath('/tmp/path1'), 100)
setTimeout(() => changePath('/tmp/path2'), 200)
setTimeout(() => console.log(watcher.getWatched()), 300) |
Describe the bug
Background: I have a long running process (days/months) that will dynamically add and remove dirs to watch. I use
.add()
and.unwatch()
for the two operations andgetWatched()
to retrieve the list of dirst watched at any given moment.Problem:
.unwatch()
does not remove the files from the list thatgetWatched()
returns, but the files are indeed not matched anymore.The problem is two fold:
getWatched()
is not reliablethis._watched
Map
will continue to grow over the lifespan of the processVersions:
To Reproduce:
Expected behavior
Actual behavior
Additional context
Again, the actual behavior of the watching (the important part) is correct, just the output of
getWatched()
is incorrect. I believe that happens because of the use of ignored paths.chokidar/index.js
Lines 485 to 488 in 0f163b8
While I could technically ignore the output of
getWatched()
, or even better, patch the library with aMy main concern is that the long running process may leak arbitrary resources (file watchers, etc) across the system.
The text was updated successfully, but these errors were encountered: