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

ENOSPC: System limit for number of file watchers reached #2072

Open
jamesikanos opened this issue Mar 27, 2024 · 9 comments
Open

ENOSPC: System limit for number of file watchers reached #2072

jamesikanos opened this issue Mar 27, 2024 · 9 comments
Labels
type: bug Something isn't working

Comments

@jamesikanos
Copy link

jamesikanos commented Mar 27, 2024

ENOSPC: System limit for number of file watchers reached caused by NX opening far too many INOTIFY watchers.

NX has over 20,000 registered watchers. Suspect node_modules folder is being watched.

Current Behavior

When the NRWL extension is activated in my NX project (containing several Angular and NodeJS Express projects) I'm seeing that there are several thousand inotify watchers. This regularly causes my Angular Serve commands to fail because it is unable to register enough watchers for it's own purposes.

For example: nrwl.angular-console-18.18.0/nxls/main.js uses 21842 Inotify Watchers whereas nx serve uses less than 1000.

I suspect that NX is watching the node_modules directory. I have added "node_modules/" to an .nxignore file in the root of my project but this doesn't seem to have an impact.

Disabling the NX Extension in VSCode fixes the issue (because none of the watchers are being registered).

Expected Behavior

I do not expect NX VS Code extension to be registering so many INotify watchers causing my other activies to fail.

Steps to Reproduce

  1. Create a VS Code Dev Container (Image: mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye)
  2. Add a post create command of "yarn global add nx && yarn"
  3. Install the NX Extension within the Dev Container (add it to the
  4. Create a project with 3 Angular apps, and 2 back end NodeJS Express apps
  5. Reload the VS Code window
  6. Run the script here which counts the number of active INOTIFY watchers.
  7. Observe that NX is using a large amount of INOTIFY watchers

Failure Logs / Images / Videos

When the error occurs, nx serve (or nx build --watch) on the angular projects give many thousand error lines saying:

ENOSPC: System limit for number of file watchers reached

Environment

Node : 20.11.1
OS : linux-x64
yarn : 1.22.19

nx (global) : 18.1.3
nx : 18.1.2
@nx/js : 18.1.2
@nx/jest : 18.1.2
@nx/linter : 18.1.2
@nx/eslint : 18.1.2
@nx/workspace : 18.1.2
@nx/angular : 18.1.3
@nx/cypress : 18.1.2
@nx/devkit : 18.1.2
@nx/esbuild : 18.1.2
@nx/eslint-plugin : 18.1.2
@nx/express : 18.1.2
@nx/node : 18.1.2
@nx/storybook : 18.1.2
@nrwl/tao : 18.1.2
@nx/web : 18.1.2
@nx/webpack : 18.1.2
typescript : 5.3.3

Community plugins:
@storybook/angular : 7.6.10

The following packages should match the installed version of nx

  • @nx/angular@18.1.3
  • @nrwl/angular@18.1.3

To fix this, run nx migrate nx@18.1.3

  • Nx Console version: v18.18.0
  • VSCode version: v1.87.2 - Ubuntu 22.04 LTS

Note: Follow up, I ran the migrate to 18.1.3 of nx/angular and still getting the same issue

@jamesikanos jamesikanos added the type: bug Something isn't working label Mar 27, 2024
@MaxKless
Copy link
Collaborator

Hey thanks for the report :) Is there something in your .yarn/cache folder? If yes, try adding that to .nxignore too. I'm reworking the watching process right now so this should be fixed in the next release.

@jamesikanos
Copy link
Author

No, there is no .yarn/cache folder.
I see a .yarn/releases folder with 1 file in there: yarn-1.22.19.cjs @ 5.1mb.

Thank you for looking into this!

@MaxKless
Copy link
Collaborator

:) Does it say which files are being watched? Is it really node_modules?

@jamesikanos
Copy link
Author

Is it really node_modules?

I am fairly confident.

I opened the file /proc/1641254/fdinfo/31 where 161254 is the PID for the node nx-console process launched inside the dev container. This file has over 20,000 inotify handles listed.

I picked some lines at random from that file to see an output like this:

inotify wd:1386 ino:620714 sdev:10300002 mask:3ce ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:140762004f31d27d
inotify wd:1385 ino:620716 sdev:10300002 mask:3ce ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:160762009c51bf25
inotify wd:1384 ino:620713 sdev:10300002 mask:3ce ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:1307620001620b39
inotify wd:1383 ino:621c31 sdev:10300002 mask:3ce ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:311c62001e6e829c

Then, using a simple script, I traced back the inode for those files, and each of them was a file inside node_modules:

  • 621c2f = /node_modules/@babel/preset-env/node_modules/@babel/plugin-transform-reserved-words/node_modules/@babel/core/lib/config/validation
  • 620714 = /node_modules/@babel/preset-env/node_modules/@babel/plugin-transform-reserved-words/node_modules/@babel/core/lib/config
  • 601130 = /node_modules/zone.js

Hope this helps.

@MaxKless
Copy link
Collaborator

Hey I just released some changes to file watching in Nx Console. Can you check and see whether this issue persists on the latest version?

@ahmedyouseeff
Copy link

I have the same problem with the latest version of NX Console

@MaxKless
Copy link
Collaborator

MaxKless commented May 2, 2024

@ahmedyouseeff can you paste your nx report as well as VSCode logs?

@tonmanna
Copy link

tonmanna commented May 7, 2024

I tried to upgrade to version 19.0.0 and did not consume much watcher for my angular + nodejs projects.
For my case after run "nx report"
I got the recommend to fix the dependency on difference version

"The following packages should match the installed version of nx

  • @nrwl/devkit@17.1.3"

I'm remove the old dependency by "rm -rf node_module/@nrwl/devkit"
Then npm install everything back to normal not rerquire to add more watcher.

@MaxKless
Copy link
Collaborator

MaxKless commented May 7, 2024

@ahmedyouseeff @jamesikanos can you reproduce this issue on the latest version of Nx Console (and if you can, Nx) anymore?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants