[rush] rushd: every rushx-client script takes exclusive workspace admission (serializing scripts and failing builds), and rushx-client hangs when a script leaves a background process holding its output
Summary
Two P1 problems with rushx-client on the daemon path. Both break the common "leave a dev server or watcher running and keep building" workflow, which native rushx supports because it takes no Rush lock.
Every rushx script takes EXCLUSIVE workspace admission for its whole lifetime. rushx requests are
commandOrigin: 'custom', andclassifyRushCommandfails closed, so any non-built-in command is classifiedRequestExclusivityClass.Exclusive(libraries/rush-daemon/src/RushCommandRequestPolicy.ts:57-60, acquired inGlobalCommandRequestRouter.ts:106-112). The README also says so ("They use exclusive global admission"). As a result:- a long-running script (dev server,
test --watch, or any 20 s script) serializes every other rushx script; - it blocks every
rush-client build, which then fails with exit 1 after the 30 s wait-timeout.
Measured with a 20 s script: a concurrent
rushx-client echo-argsended at 21.3 s instead of about 1 s, a second concurrentslowscript ended at 40.9 s, andbuild --only p01ended at 22.0 s.- a long-running script (dev server,
rushx-client hangs if the script leaves a background descendant holding stdout/stderr (for example
cmd &ornohup).- The daemon spawns scripts with
stdio: 'pipe'and treats the child as finished only on'close'(GlobalCommandExecutionContext.ts:362). Node emits'close'only after every holder of the pipes has closed them. Sobash -c "(sleep 120 &) ; echo started"exits immediately, but the request stays open for 10-121 s, holding the exclusive lease from item 1 the whole time. - On cancel,
SubprocessTerminator.killProcessTreereturns early because the direct child has already exited (node-core-librarySubprocessTerminator.ts:124-127), so the process-group SIGKILL is skipped and the descendant stays orphaned. - Native rushx uses inherited stdio and returns when the process exits.
- The daemon spawns scripts with
Repro steps
cd <ws>/packages/p01 # scripts: "slow": 20 s sleep; "bg": "bash -c \"(sleep 120 &) ; echo started\""
rushx-client slow & sleep 2
rushx-client echo-args x & # should take ~1 s -> ends at ~21 s
rush-client build --only p01 # waits behind the script; fails after 30 s for longer scripts
rushx-client bg # native returns immediately; the daemon path hangs until the sleep endsExpected result: rushx scripts don't hold an exclusive workspace lease for their whole lifetime; they don't need the build graph at all. A request completes when the script process exits, not when every descendant closes the inherited pipes. On cancel, the script's whole process group, including daemonized descendants, is terminated gracefully.
Actual result: As described above.
Details
Suggested fix:
- Classify rushx script execution as a non-exclusive class, taking at most a shared/read lease while the environment is prepared, and release it before the script runs.
- Complete the request on
'exit'plus a bounded drain of the pipes, rather than waiting for'close'. - Always kill the child's process group on cancel, even when the direct child has already exited.
A load-time prototype patch showed the gains:
- two concurrent 20 s scripts went from 41 s to 21.5 s;
- the background-descendant script went from 121 s to 1.4 s;
- a script's Ctrl+C handler now runs (related: #6074).
Graph reloads still wait for running scripts, so a complete fix also needs the reload path to not require exclusivity over rushx.
This was found during an automated performance/behavior analysis of rush-client/rushd on Linux, and both items were 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