nx-console icon indicating copy to clipboard operation
nx-console copied to clipboard

ENOSPC: System limit for number of file watchers reached

Open jamesikanos opened this issue 1 year ago • 7 comments

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

To fix this, run nx migrate [email protected]

  • 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 avatar Mar 27 '24 10:03 jamesikanos

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.

MaxKless avatar Mar 27 '24 11:03 MaxKless

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!

jamesikanos avatar Mar 27 '24 11:03 jamesikanos

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

MaxKless avatar Mar 27 '24 12:03 MaxKless

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.

jamesikanos avatar Mar 27 '24 13:03 jamesikanos

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?

MaxKless avatar Apr 15 '24 09:04 MaxKless

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

ahmedyouseeff avatar Apr 30 '24 13:04 ahmedyouseeff

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

MaxKless avatar May 02 '24 09:05 MaxKless

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

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.

tonmanna avatar May 07 '24 06:05 tonmanna

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

MaxKless avatar May 07 '24 08:05 MaxKless

Hey :) After our watching changes, this should be resolved so I'll close this issue for now. Please do let me know if you still run into it and I will investigate further! Thanks a lot

MaxKless avatar Jun 26 '24 12:06 MaxKless

Hi, I got the same issue when I upgrade from [email protected] to [email protected]. In a monorepo with multiple nextjs application, when runnning "nx dev" the file watchers limit were reached. As soon as I downgraded to 19.1.1 it was working as expected (no watchers were added).

slevy85 avatar Jul 14 '24 11:07 slevy85

is this happening only with Nx Console installed? Or also with just nx? If yes, could you create an issue in the nx repo?

MaxKless avatar Jul 15 '24 08:07 MaxKless