[rush] rushd (Linux): RUSH_DAEMON_WATCH=1 creates one inotify watch per file (including build outputs) via Node's recursive fs.watch emulation and blocks the event loop
Summary
With RUSH_DAEMON_WATCH=1, WorkspaceSessionFileWatcher watches each warm project folder with fs.watch(folder, { recursive: true }). On Linux, Node 22 implements recursive watching in JavaScript (internal/fs/recursive_watch). It walks the whole tree synchronously (readdirSync) and calls fs.watch() on every file and directory, including build outputs (lib*, dist, temp) and node_modules entries. Ignore rules (.git, node_modules) are applied only when events arrive, not at registration time.
Measured in a rushstack clone:
- 5,140 inotify watches for 20 warm projects, peaking at 12,119;
- about 35,000 for all project folders, which exceeds the historical default
fs.inotify.max_user_watches=8192(older kernels, many containers and CI images); @microsoft/rush-libalone needs 6,250;- while a watched project writes outputs, the daemon's event loop is swamped, and
daemon statuslatency spiked to 5.7 s (0.98 s max with watch off); - a synchronous walk of all folders blocked the event loop for about 100 s in our measurement.
Separately, fs.watch sometimes throws ENOENT scandir .../lib when lib/ is recreated. That permanently marks the watcher unhealthy and forces a tier-1 reload.
Repro steps
In a rushstack clone, with RUSH_DAEMON_WATCH=1 set when the daemon starts:
- Run
rush-client build --to @rushstack/node-core-librarytwice, then--to @rushstack/hefttwice. - Count the
^inotifylines in/proc/<daemon pid>/fdinfo/*after each step.
Results: 28 → 798 → 10,236 → 12,119 → 5,140. With watch off, the count stays at 28.
Expected result: Watch cost is proportional to source directories. Outputs, .rush/temp and node_modules are never watched, there is no risk of ENOSPC, and the event loop is not blocked. An ENOSPC error is surfaced in daemon status.
Actual result: One watch per file, and event-loop stalls.
Details
Root cause (main @ 60007c9a8c): libraries/rush-daemon/src/WorkspaceSessionFileWatcher.ts:52, :97, :170 uses Node's recursive fs.watch for whole project folders, and :209-215 filters paths only at event time.
Suggested fix: on Linux, create non-recursive directory watchers yourself. An inotify watch on a directory already reports changes to its child files. Walk asynchronously and skip node_modules, .git, the declared output folders and .rush/temp. Alternatively, watch only git-tracked input directories taken from the input snapshot. A prototype of the directory-level async watcher cut watches 11x (32,822 → 2,921 for 182 projects) and reduced the maximum event-loop block from 100.9 s to 22 ms.
This was found during an automated performance/behavior analysis of rush-client/rushd on Linux and independently confirmed.
Standard questions
| Question | Answer |
|---|---|
@microsoft/rush globally installed version? |
built from main @ 60007c9a8c (5.179.0) |
rushVersion from rush.json? |
5.179.0 |
pnpmVersion, npmVersion, or yarnVersion from rush.json? |
[email protected] |
(if pnpm) useWorkspaces from pnpm-config.json? |
true |
| Operating system? | Linux (WSL2 Ubuntu 24.04) |
| Would you consider contributing a PR? | Yes |
Node.js version (node -v)? |
22.23.2 |
Source: microsoft/rushstack