question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Watchpack 2.0.0-beta.13 fails on large codebase with "too many open files" error

See original GitHub issue

With Webpack 4 and Watchpack 1.x we avoided this error by applying a patch to Watchpack to use sane instead of chokidar, which in combination with Facebook’s watchman 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 with chokidar. 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: https://github.com/nodejs/node/issues/29460

I 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?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
sokracommented, Aug 6, 2020

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.

1reaction
sokracommented, Jul 29, 2020

Seems like it’s using some “other” limit we are not aware of. I also found launchctl limit maxfiles, maybe you can try printing that limit.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix the 'Too Many Open Files' Error in Linux?
It means that a process has opened too many files (file descriptors) and cannot open new ones. On Linux, the “max open file...
Read more >
Fixing the “Too many open files” Error in Linux - Baeldung
When working with Linux servers, we may encounter the “Too many open files” error. In this article, we'll go over what this error...
Read more >
How to solve "Too many Open Files" in Java applications
The error Java IOException “Too many open files” can happen on high-load servers and it means that a process has opened too many...
Read more >
node and Error: EMFILE, too many open files - Stack Overflow
After a number of searches I found a work around for the "too many open files" problem: var requestBatches = {}; function batchingReadFile(filename,...
Read more >
Fix 'EMFILE: too many open files' error in Jest - SeanMcP.com
Jul 29, 2020. Fix 'EMFILE: too many open files' error in Jest. When I tried to run jest --watch in a codebase, I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found