-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
Watchpack 2.0.0-beta.13 fails on large codebase with "too many open files" error #169
Comments
Which OS? If you are on MacOS, the max file limit it very low by default and we recommend to increase it (watchman does it automatically).
All the linked issues are closed. Which bugs are you talking about exactly? |
Yep, aware of the I've dug in further by adding additional logging to |
It's definitely an issue with the way Watchpack installs watchers. When I created a simple test script that'll call
This is with a I will try and put together a minimal reproduction today with a similar setup if that helps. I am also trying to find out from a co-worker if they get the same issue on Linux with the same repro script I'm using. Edit: interestingly some further digging shows that it falls over if more that 4,096 |
OK, here's a repro which fails on macOS (not just my machine, I've tried it with some colleagues) regardless of how high (or low) you set the max open files limit: https://github.com/marcins/webpack-fs-watch-error-repro (FYI @sokra) (I had a colleague with the default limit of 256 try it - works with 4000 dirs, fails with 4096, same as with 10k or 200k max open files limit) |
Seems like it's using some "other" limit we are not aware of. I also found I think a good solution is to merge watchers to recursive watchers when supported until we stay within a limit of watchers (I think 500 would be fine, so you can technically run 8 processes with watchpack). As it seems like only osx is the problem and it supports recursive watchers that should work fine. I want to avoid recursive watchers by default as they 1. are not always supported, 2. watch too much and we don't know how deep your directories are, which could have performance implications. |
That might be something worth testing, whether this is a global or per-process limit.
Yep, definitely wouldn't be a default - but they are supported on Windows & macOS (according to the Without only a surface understanding of how Webpack / Watchpack code interacts (though I have dug through it a little bit), I can imagine that it should be possible to process the list of files to be watched and narrow down to a set of common roots that will cover everything needed - though I guess the problem in the real world is all the different and wonderful way people set up their projects might mean that common root is higher in the filesystem than you might want it. As you suggest though, potentially you don't need to go all the way to common roots, just enough to stay under the limit. This would definitely be a blocker for adoption of Webpack 5 for us (though at the moment we're just evaluating the work required to migrate). I will likely unblock myself for now by hacking in a recursive directory watch for the project root which should be enough for my evaluation. |
This is interesting, it looks like there was a proposed changed many years ago to implement a single It also refers to a total limit of |
I think I fixed the issue. I added a merging algorithm which merges watchers into recursive watchers when reaching the watcher limit. I wrote a test and got the same results as you, only OSX has this limit of watchers. The test passes now with the new algorithm. |
Hey @sokra, I think the issue is still not fixed in Webpack 5. We described it here: martpie/next-transpile-modules#236 The only thing that helps is setting this in our Next config file:
The project has thousands of files, possibly crossing 10.000 watched files. Using macOS, Webpack 5, latest Next.js, Next Transpile. Thank you |
I'm facing this issue on linux when using Angular and Steps to reproduce:
and the terminal gets inundated with these "too many open files" errors. I have tried running
before it, but the error persists |
Why is this closed?? |
This does not seem resolved to me either. |
We still bump into this issue using Angular 13 & 14. So I hope it can be re-opened? |
This shouldn't be closed. @php4fan identical steps, same issue.
|
With Webpack 4 and Watchpack 1.x we avoided this error by applying a patch to Watchpack to use
sane
instead ofchokidar
, which in combination with Facebook'swatchman
worked for us.However Webpack 5 + Watchpack 2 uses Node native
fs.watch
which seems to end up in the same "too many open files" issue as we had before withchokidar
. After a build with Webpack dev server the console just starts repeating:Watchpack Error (watcher): Error: EMFILE: too many open files, watch
There are known existing bugs with Node's
fs.watch
and many files: nodejs/node#29460I can work around this by using
poll
instead for testing - but that's not sustainable due to the CPU overhead.Would there be any interest in supporting watchman as a watcher "natively" to avoid another dependency on something like
sane
? If not, what would your recommendation be for large projects?The text was updated successfully, but these errors were encountered: