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.

EMFILE: too many open files, watch cypress.json

See original GitHub issue

Description

I know there is an advise for this the problem, but I cannot fix it. The open command should just work and it seems to be a node_module cypress uses. Please, have a look.

Error

Error: EMFILE: too many open files, watch

Facts

I have set redicolously high values for ulimits

❯ ulimit -n
500000
❯ sudo sysctl -a | grep fs.file-max
fs.file-max = 9223372036854775807
❯ cat /proc/sys/fs/inotify/max_user_watches
524288

Looks like this fs.watch ist not async:

102 function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
103   const handleEvent = (rawEvent, evPath) => {
104     listener(path);
105     emitRaw(rawEvent, evPath, {watchedPath: path});
106 
107     // emit based on events occurring for files from a directory's watcher in
108     // case the file's watcher misses it (and rely on throttling to de-dupe)
109     if (evPath && path !== evPath) {
110       fsWatchBroadcast(
111         sysPath.resolve(path, evPath), KEY_LISTENERS, sysPath.join(path, evPath)
112       );
113     }
114   };
115   try {
116     return fs.watch(path, options, handleEvent);
117   } catch (error) {
118     errHandler(error);
119   }
120 }

Current behavior

npx cypress open
❯ npx cypress open
[313284:0608/135242.546859:ERROR:proxy_config_service_linux.cc(607)] inotify_init failed: Zu viele offene Dateien (24)
[313284:0608/135242.547107:ERROR:file_path_watcher_linux.cc(315)] inotify_init() failed: Zu viele offene Dateien (24)
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[313284:0608/135243.947389:ERROR:proxy_config_service_linux.cc(607)] inotify_init failed: Zu viele offene Dateien (24)
Error: EMFILE: too many open files, watch '/datadisk/projects/cypress/first_test/cypress.json'
    at FSWatcher.<computed> (internal/fs/watchers.js:218:26)
    at Object.watch (fs.js:1525:34)
    at createFsWatchInstance (/home/markus/.cache/Cypress/7.5.0/Cypress/resources/app/packages/server/node_modules/chokidar/lib/nodefs-handler.js:116:15)
    at setFsWatchListener (/home/markus/.cache/Cypress/7.5.0/Cypress/resources/app/packages/server/node_modules/chokidar/lib/nodefs-handler.js:163:15)
    at NodeFsHandler._watchWithNodeFs (/home/markus/.cache/Cypress/7.5.0/Cypress/resources/app/packages/server/node_modules/chokidar/lib/nodefs-handler.js:325:14)
    at NodeFsHandler._handleFile (/home/markus/.cache/Cypress/7.5.0/Cypress/resources/app/packages/server/node_modules/chokidar/lib/nodefs-handler.js:355:23)
    at NodeFsHandler._addToNodeFs (/home/markus/.cache/Cypress/7.5.0/Cypress/resources/app/packages/server/node_modules/chokidar/lib/nodefs-handler.js:617:21)
    at /home/markus/.cache/Cypress/7.5.0/Cypress/resources/app/packages/server/node_modules/chokidar/index.js:435:21
    at Function.all (<anonymous>:null:null)
 {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  path: '/datadisk/projects/cypress/first_test/cypress.json',
  filename: '/datadisk/projects/cypress/first_test/cypress.json'
}
Error: EMFILE: too many open files, watch '/datadisk/projects/cypress/first_test/cypress.json'
    at FSWatcher.<computed> (internal/fs/watchers.js:218:26)
    at Object.watch (fs.js:1525:34)
    at createFsWatchInstance (/home/markus/.cache/Cypress/7.5.0/Cypress/resources/app/packages/server/node_modules/chokidar/lib/nodefs-handler.js:116:15)
    at setFsWatchListener (/home/markus/.cache/Cypress/7.5.0/Cypress/resources/app/packages/server/node_modules/chokidar/lib/nodefs-handler.js:163:15)
    at NodeFsHandler._watchWithNodeFs (/home/markus/.cache/Cypress/7.5.0/Cypress/resources/app/packages/server/node_modules/chokidar/lib/nodefs-handler.js:325:14)
    at NodeFsHandler._handleFile (/home/markus/.cache/Cypress/7.5.0/Cypress/resources/app/packages/server/node_modules/chokidar/lib/nodefs-handler.js:355:23)
    at NodeFsHandler._addToNodeFs (/home/markus/.cache/Cypress/7.5.0/Cypress/resources/app/packages/server/node_modules/chokidar/lib/nodefs-handler.js:617:21)
    at /home/markus/.cache/Cypress/7.5.0/Cypress/resources/app/packages/server/node_modules/chokidar/index.js:435:21
    at Function.all (<anonymous>:null:null)

Desired behavior

Just run cypress as described in docu.

Test code to reproduce

Follow docu to install cypress

  • npm install
  • npx cypress open

Versions

❯ node --version
v16.3.0
❯ npm --version
7.15.1
* Cypress/7.5.0
OS
Linux  5.8.0-55-generic #62~20.04.1-Ubuntu SMP Wed Jun 2 08:55:04 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
marmelincommented, Jun 11, 2021

[SOLVED] ✔️ Fixed with fs.inotify.max_user_instances = 256

For Linux:

Check current value of max_user_instances: $ cat /proc/sys/fs/inotify/max_user_instances increase that value: $ echo 256 > /proc/sys/fs/inotify/max_user_instances

Note: sudo … does not work, you have to switch to root or use sudo su -c ...

In order to make that change permanent add a line to /etc/sysctl.conf: fs.inotify.max_user_instances = 256

0reactions
jennifer-shehanecommented, Jun 11, 2021

@marmelin Thanks for sharing your solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

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( ......
Read more >
cypress-io/cypress - Gitter
Error: EMFILE: too many open files, open '/Users/jhanink/projects/pl/pl-cypress-shared/node_modules/faker/package.json'. Kelly Hale.
Read more >
Error: EMFILE: too many open files, watch - Elixir Forum
This message gets displayed for every file in the assets directory, when starting the dev instance. If I stop other running programs, close ......
Read more >
Changelog - Cypress Documentation
Cypress will no longer watch files when executing component tests in "run" mode ... Fixes #23146; Add delay to header tooltips so they...
Read more >
Watchpack Error (watcher): Error: EMFILE: too many open files
... Error (watcher): Error: EMFILE: too many open files" - NextJS-node.js. Search. score:0. I had a similar issue but without address after 'watch'....
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