[rush] rush-cli-client: daemon recovery and management gaps (stale artifacts permanently disable the daemon; daemon stop/restart are not idempotent)
Summary
The daemon's fail-closed ownership checks are deliberately conservative. However, some states that are provably safe to recover from still disable the daemon permanently for a workspace, and there is no documented recovery command. The management commands are also not idempotent.
- Stale or foreign artifacts permanently disable the daemon (after
kill -9of the daemon plus partial cleanup or PID reuse):- a socket with no
pid.jsongivesSocket ... has no ownership record; refusing automatic reclaim. Using in-process Rush.on every build (+2 s), anddaemon startrefuses too; - a corrupt
pid.jsongives a permanent fallback (Cannot safely read ...pid.json; refusing automatic reclaim.); - a
pid.jsonnaming a reused live, unrelated PID costs 16.5 s per command (PID ... still exists but the daemon is not ready. It may be a reused PID; refusing to kill it...) until that unrelated process exits.
- a socket with no
daemon stopanddaemon restartfail when no daemon is running. Both exit 1 withCould not connect ..., andrestartdoes not start a daemon. Scripts and agents must special-case "not running" for the commonstop; ...; startand "restart to pick up config" flows.
Repro steps
# RUSH_DAEMON=1, rush-client from main @ 60007c9a8c
rush-client daemon stop; rush-client daemon stop; echo $? # 1 "Could not connect"
rush-client daemon restart; echo $? # 1, no daemon started
rush-client build; kill -9 <daemon pid>; rm <runtime dir>/rushd-<key>.pid.json
rush-client build # permanent in-process fallback + warning Expected result: Self-heal whenever it is provably safe, and otherwise provide an explicit, documented escape hatch that the fail-closed messages point to. stop succeeds (exit 0, state: "notRunning") when nothing is running, and restart starts a daemon when none is running.
Actual result: A manual, undocumented cleanup of files in $XDG_RUNTIME_DIR/rushd-<uid>/ is required. The management commands exit 1.
Details
Root cause (main @ 60007c9a8c): assertNoLiveOwner / readDaemonOwnership in libraries/rush-client-core/src/connectOrStartDaemon.ts:282-323 fail closed in all three cases, and waitForHandoffAsync (:257-276) polls a live foreign PID until the 15 s deadline. The management commands are in apps/rush-cli-client/src/daemonCommands.ts.
Suggested fix:
- PID reuse: compare
pid.jsonstartedAtwith the process start time (LockFilein node-core-library already hasgetProcessStartTime). A mismatch means the owner is dead, so reclaim. - Socket without a record, or a corrupt record, combined with
ECONNREFUSEDwhile holding the start mutex (and no.startingreservation): no listener exists, so reclaim. - Add
rush-client daemon stop --force(ordaemon reset) that removes this workspace's artifacts after verifying that no process in the recorded session is alive, and mention it in every fail-closed message. - Make
stopidempotent, and makerestartstart a daemon when none is running.
This was found during an automated performance/behavior analysis of rush-client/rushd on Linux and independently reproduced. Related: #6050 (durable .starting reservation).
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