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

Recursive fs.watch for linux #36005

Closed
fabiospampinato opened this issue Nov 6, 2020 · 7 comments · Fixed by #45098
Closed

Recursive fs.watch for linux #36005

fabiospampinato opened this issue Nov 6, 2020 · 7 comments · Fixed by #45098
Labels
fs Issues and PRs related to the fs subsystem / file system.

Comments

@fabiospampinato
Copy link

fabiospampinato commented Nov 6, 2020

Is your feature request related to a problem? Please describe.

File system watching is a core part of many kinds of node apps, currently fs.watch is close to providing everything needed for watching files and directories easily, but not supporting recursive watching under Linux is a deal breaker.

Describe the solution you'd like

The recursive option of fs.watch should be supported under Linux too.

Describe alternatives you've considered

There are no great alternatives really, file system watching is a mess and Node should handle it reliably, the only other option is to use a third-party filesystem watcher or write one, all the ones I've tried are either unreliable in some way, come with a big performance downside under some scenarios, or rely on some native dependency that's a pain to work with for cross-platform apps.


If this issue is a duplicate I couldn't find the original one.

@mmomtchev
Copy link
Contributor

@fabiospampinato, I think this issue belongs to https://github.com/libuv/libuv which provides the underlying feature. The problem is however, that the native interfaces - FSEvents on OSX and ReadDirectoryChangesW on Windows provide recursive events, while with inotify on Linux, this is left to the user-level implementation which has to open a file descriptor on every watched directory. There is also the problem of multiple nested directories created in quick succession, an event which cannot be monitored for on Linux in a reliable way. But you should ask the libuv developers about that.

@fabiospampinato
Copy link
Author

I think this issue belongs to libuv/libuv which provides the underlying feature.

It looks like there was an issue about this but it didn't receive much consideration: libuv/libuv#1778

IMO there should be an issue about this in Node's repo too, since Node already provides recursive watching support for macOS and Windows, obviously ideally Linux distros should be supported too.

Whether the implementation comes from a dependency of Node or Node itself I don't think it matters for actual users, and whether this feature can be implemented perfectly or not I would argue doesn't matter much either because if it can't be implemented perfectly Linux users are still going to need some sort of recursive watching, it's no coincidence that stuff like chokidar have ~30M weekly downloads.

If we agree that this is a feature Node should provide, and libuv doesn't want to code it, what should Node do then?

@renhiyama
Copy link

Any updates? For linux I wonder if it would be possible to get all the folders recursively and run a for loop on each of them?

@anonrig
Copy link
Member

anonrig commented Oct 19, 2022

I’m working on this issue.

@JYone3A
Copy link

JYone3A commented Nov 17, 2023

One question, I wonder why inotifywait is not used on Linux as it does support recursion? Wouldn't that probably be more performant?

@anonrig
Copy link
Member

anonrig commented Nov 17, 2023

One question, I wonder why inotifywait is not used on Linux as it does support recursion? Wouldn't that probably be more performant?

Yes it will be but this change needs to be implemented in libuv.

@JYone3A
Copy link

JYone3A commented Dec 1, 2023

Ah, thanks. I'm asking because right now I am confused - how to know when all notifiers have been set up (using the fsPromises version)?

I am currently using Chokidar, but I guess its much slower as it manually sets up watches for each file in the recursive mode (I guess that's necessary to support the depth configuration option).

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

Successfully merging a pull request may close this issue.

6 participants