Repository navigation
Description
Summary
When Rush restores an operation from a local build cache entry with tar, it extracts the entry into a staging folder, <project>/.rush/temp/build-cache-restore-XXXXXX/, and moves the output folders into place from there. The staging folder is deleted only in a finally block. If the process is interrupted during the restore (Ctrl+C on a slow first rush build or rush start, or SIGKILL), the folder stays behind with a partial or full copy of the outputs (lib*, dist, ...). Nothing removes it later, and later interrupted restores add more. Tools that scan the project folder then pick up stale copies of build outputs. For example, a lint step that globs the project folder linted the .js files in it and failed every later build of that project until the folder was deleted by hand.
Versions
@microsoft/rush5.181.0 (observed with theuseDirectFileTransfersForBuildCacheexperiment on). On main, the staged restore is used for every restore of a local cache entry with tar.- Linux, Node.js 22
Repro
- Use a build cache that has an entry for a project with large outputs, and delete that project's output folders.
- Run
rush build -t <project>and press Ctrl+C (orkill -INT <pid>) while the project is being restored from the cache. - Look in
<project>/.rush/temp/: abuild-cache-restore-XXXXXXfolder with the outputs is there, and it is still there after any laterrush build.
In one interrupted rush start we saw five such folders (the largest 53 MB); each folder's mtime matched the interrupt.
Expected
An interrupted restore leaves no copy of the outputs where project tooling looks, or the next restore removes it.
Actual
The staging folders stay in <project>/.rush/temp/ indefinitely.
Code pointer (main)
libraries/rush-lib/src/logic/buildCache/StagedRestore.ts, lines 79-80 (mkdtemp(path.join(projectRushTempFolder, STAGING_FOLDER_PREFIX))) and lines 108-115: the only cleanup is thefinallyblock, which does not run when the process is killed or exits on a signal.- Called from
libraries/rush-lib/src/logic/buildCache/OperationBuildCache.ts, around line 408.
Suggested fix
Any of:
- Before staging a restore, delete stale
build-cache-restore-*folders in the project's.rush/tempfolder: for example, include the process id in the folder name and delete the folders whose process is no longer running (several phases of one project can restore at the same time). - Stage in a folder outside the project (for example under the common temp folder, on the same volume so the renames still work), so an interrupted restore never leaves files where project tooling looks.
- Also delete the staging folder from the abort/signal path where possible.
Workaround: exclude .rush/** from tools that scan the project folder.
Filed with help from GitHub Copilot (AI); reviewed by the reporter.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNeeds triage
Activity