Description
Summary
When a Node.js runtime download is interrupted (the process gets SIGTERM or SIGKILL), its staging directory $VP_HOME/js_runtime/.tmpXXXXXX/ stays on disk with the partial node-vX.Y.Z-<os>-<arch>.tar.gz in it. Nothing removes it later: a successful install of the same version afterwards leaves the old .tmp* directories in place.
If something keeps calling a shim with a short timeout, the directories add up quickly. On my machine they filled the disk.
Reproduction (vp v1.6.0, macOS 27.2, arm64)
R="$HOME/.local/share/vite-plus/js_runtime"
vp env exec --node 24.22.1 node -v >/dev/null 2>&1 & # any version not yet installed
pid=$!; sleep 2.5; kill -TERM $pid # -KILL gives the same result
sleep 2; ls -A "$R"; ls -la "$R"/.tmp*
# -> .tmpAIgHeO/node-v24.22.1-darwin-arm64.tar.gz (27 MB) remains
vp env exec --node 24.22.1 node -v # completes normally
ls -A "$R"
# -> .tmpAIgHeO is still thereHow it hit me
A Claude Code status line runs $VP_HOME/bin/node <script> every 5 s. The host kills it when it overruns its budget. When a new Node LTS (26.14.0) was published, the shim resolved it, started downloading it, and was killed on every refresh before it could extract. Over about 4 hours this left 3274 .tmp* directories (~132 GB) in js_runtime/, all holding the same partial tarball. The loop stopped only when one call happened to finish.
Workaround: pin with vp env default <version> so a shim call never starts a download.
Suggested fixes
- Clean up stale staging directories: when an install starts (or from
vp env clean), removejs_runtime/.tmp*directories that no live process holds. The per-version.lockshould already show whether an install is in progress. - Reuse or resume a download that was already partly fetched, instead of starting a new temp directory each time.
- Optional: when a shim call would have to download a runtime, print a one-line notice to stderr. Then an unattended caller that keeps re-triggering the download is visible.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Effort
Target date
Start date
Activity
voidzero-bot commentedon Dec 1, 2026
main(vp v1.8.0), with SIGTERM and SIGKILL mid-download (throttled local mirror viaVP_NODE_DIST_MIRROR, since the runner's network finishes a real download in ~3 s)crates/vp_js_runtime/src/staging.rs(staging cleanup), plus an end-to-end regression test incrates/vp_js_runtime/src/runtime.rsand a CLI snapshot fixture incrates/vp_cli_snapshots/.../command_env_clean/vp env default <version>prevents the downloads entirely — but for that usage the disk fills at roughly a gigabyte per hour, so the residue is worth cleaning up.The root cause is in
crates/vp_js_runtime/src/runtime.rs(~line 241): each runtime download stages into atempfile::TempDircreated directly under$VP_HOME/js_runtime, and cleanup relies solely on theTempDirdestructor at normal function exit. SIGTERM/SIGKILL terminate the process without running destructors, so the.tmpXXXXXXdirectory with its partial tarball survives — and nothing ever removes it: a later successful install of the same version early-returns or publishes viamove_to_cachewithout scanning.tmp*, andvp env cleanenumerates only version directories underjs_runtime/node, so leftovers are invisible to it. All entry points (the<DATA>/bin/nodeshim,vp env exec,vp env use/pin,vp self setup) funnel into the same function, so every killed attempt leaks one staging directory — which is how 3274 dirs (~132 GB) piled up in the linked report.I found a potential fix for this issue. Staging directories only ever exist while their version's installation lock is held, so the fix names them
.tmp-<provider>-<version>-<rand>, removes same-version leftovers under the install lock before each new download (capping residue at one directory and clearing it on the successful attempt), attributes legacy.tmpXXXXXXleftovers via the partial archive inside them, and adds a lock-checked sweep tovp env clean nodeusing a new non-blockingtry_lock_exclusiveso concurrent live installs are never disturbed. Please review the branch — this needs human review before merging.Full Triage Report
Triage report: issue #3626 — interrupted Node.js runtime downloads leave
js_runtime/.tmp*directoriesStep: reproduce — REPRODUCED (Bug, high confidence)
Issue summary. When
vp env exec --node <version>(or a shim call resolving an uninstalled version) is interrupted while downloading the Node.js runtime (SIGTERM/SIGKILL), the staging directory$VP_HOME/js_runtime/.tmpXXXXXX/with the partialnode-vX.Y.Z-<os>-<arch>.tar.gzremains on disk. A later successful install of the same version does not remove the stale.tmp*directories, so repeatedly killed callers accumulate them indefinitely (reporter: 3274 dirs, ~132 GB over 4 hours).vp env clean)..tmp*staging dirs persist forever; subsequent successful installs leave them in place.Environment: Vite+
vpv1.8.0 built from the current checkout (5cf0b72c8); Node.js v24.22.3 (runner), v24.22.1 (runtime under test); pnpm 12.11.2; Ubuntu Linux x64.Relevant source (observations at reproduction time):
crates/vp_js_runtime/src/runtime.rs(~line 241) creates the staging directory withTempDir::new_in(&cache_dir)insidedownload_runtime_with_provider. Thetempfile::TempDirdestructor only runs on normal unwind/exit; SIGTERM (exit 143) and SIGKILL bypass it, so.tmpXXXXXXunderjs_runtime/survives. No startup orvp env cleanpath scans for stale.tmp*dirs.Reproduction method. A fresh
VP_HOMEwas used so the default installation was untouched. The runner's network downloads the ~58 MB tarball in under 3 s, so a real nodejs.org download could not be interrupted reliably; the download was served by a local throttling caching mirror (64 KiB every 0.2 s) via the supportedVP_NODE_DIST_MIRRORenvironment variable. This changes only download speed, not vp behavior.Interrupt case (fresh
VP_HOME,VP_NODE_DIST_MIRROR=http://127.0.0.1:8137):Follow-up successful install of the same version:
Control case (uninterrupted install in a fresh home, full-speed download):
ls -A "$VP_HOME/js_runtime"shows onlynode— no.tmp*residue. A clean install leaves nothing behind, confirming the leftovers are caused by the interruption and that nothing in the successful-install path removes pre-existing stale staging dirs.Note on the very first attempt: killing the wrapper 3 s after starting an unthrottled real nodejs.org download did not reproduce — the install had already completed (exit 0). This was a timing artifact of the fast runner network, not evidence against the report.
Step: diagnose — root cause, confidence: high
The runtime install path stages downloads in a
tempfile::TempDircreated directly inside the cache root and relies only on the process running to completion for cleanup:crates/vp_js_runtime/src/runtime.rs:241(download_runtime_with_provider):TempDir::new_in(&cache_dir)—cache_diris<DATA>/js_runtime(crates/vp_js_runtime/src/cache.rs).tempfile3.27's default builder names the directory.tmp+ 6 random alphanumerics, matching the observed.tmpYrEfOD,.tmpVbH7Eu,.tmpe2X91Rand the reporter's.tmpAIgHeO.TempDir'sDropguard at function exit. No signal handlers are installed, so SIGTERM (143) and SIGKILL (137) terminate the process without running destructors; the staging directory and partial archive stay on disk. Both signals were tested; both leave residue..tmp*dirs:try_exists(binary_path)early return or publishes viamove_to_cache, which only touchesjs_runtime/node/<version>. Empirically confirmed:.tmpYrEfODsurvived a successful install of the same version.vp env clean(crates/vp_global_cli/src/commands/env/clean.rs,clean_node_runtimes/list_installed_versions) enumerates only version directories underjs_runtime/nodeand package-manager version dirs;.tmp*is invisible to it. Empirically confirmed:vp env cleanprinted "✓ Removed 0 Node.js runtimes" and both stale.tmp*dirs remained.<DATA>/bin/nodeshim (shim/dispatch.rs:1407),vp env exec(commands/env/exec.rs:166),vp env use/pin(use.rs:320,pin.rs:319),vp self setup(vp_setup/src/install.rs), lifecycle installs. This is exactly the reporter's status-line scenario.Additional evidence:
kill -KILLmid-download (exit 137) left a partial archive the same way. The content-integrity retry (up to 3 attempts) reuses the same staging dir within one process; the leak is per killed process, not per retry.git logonruntime.rsshows no prior cleanup attempt — an original design gap (EXDEV-safe staging with Drop-only cleanup), not a regression.Edge cases considered: concurrent installs of different versions (cleanup must not delete a peer's live staging dir); concurrent installs of the same version (the lock serializes them, so same-version cleanup under the lock is safe);
vp env cleanracing a live install; Windowsremove_dir_allon open handles. A related instance of the same pattern exists in package-manager downloads (vp_pm_cli/src/package_manager.rs:1869, 2057, 2327stage viatempfile::tempdir_in), so interrupted package-manager installs leak<DATA>/package_manager/.tmp*the same way — same bug class, separate code path.Step: verify — verdict: bug, confidence: high
No source asserts that these staging directories are meant to persist; every relevant artifact expresses the opposite intent:
rfcs/js-runtime.md, "Concurrent Download Protection", from the crate's introduction in 79194a2): the temp dir + atomic rename exist for atomic, concurrent-safe installs; nothing mentions keeping or reusing staging directories.crates/vp_js_runtime/src/download.rs:455-465,move_to_cache): "dir without binary → a stale/partial install, remove then move". The codebase deliberately removes stale partial installs under the lock; killed-process staging dirs are the same class of residue, just not covered by that cleanup.crates/vp_pm_cli/src/package_manager.rs:1860-1873): "Keep the TempDir guard alive so a failure path cleans up the temp dir". Failure-path cleanup is a stated design requirement; only the signal-kill path escapes the Drop guard.vp env cleanis documented to remove unused installs (docs/guide/env.md:204; help text "Clean all unused managed versions"), yetclean_node_runtimescannot see.tmp*.gh searchfound only this issue. This is Vite+'s own runtime-management code, not behavior forwarded from an upstream project.Step: fix — implemented on branch
triagebot/fix-3626Staging directories exist only while their version's installation lock is held (created after
lock_installation, consumed bymove_to_cache, both under the lock). This makes leftover removal precise and concurrency-safe:.tmp-<provider>-<version>-<rand>(previouslytempfile's default.tmp<rand>), so a leftover can be attributed without inspecting its contents.remove_stale_staging_dirs): while holding a version's lock, every staging dir for that version is by definition stale and is removed before the new download is staged. Staging dirs of other versions may belong to concurrent live installs and are untouched. In the reporter's loop this caps residue at the one directory the latest kill leaves, and the attempt that finally succeeds clears everything..tmp<rand>): attributed via the partial archive/extracted dir inside them (node-v<version>-<platform>...), and removed by (2) when they name the installed version, or by (4) generally.vp env cleansweep (clean_interrupted_staging_dirs, wired into thenodescope): each staging dir's version lock is taken with a new non-blockingvp_shared::file_lock::try_lock_exclusive; the dir is removed only when the lock is free, so a live install is never disturbed. Empty unattributable dirs are kept. Removals are reported asRemoved N interrupted downloadsonly when N > 0, so existingvp env cleansnapshots are unchanged.Reporter suggestions 2 (resume partial downloads) and 3 (stderr notice) are enhancements outside this minimal fix. The analogous package-manager staging leak was left as a follow-up.
Changed files:
crates/vp_shared/src/file_lock.rs(non-blockingtry_lock_exclusive+ tests), newcrates/vp_js_runtime/src/staging.rs(naming, install-time cleanup, lock-checked sweep + 5 unit tests),crates/vp_js_runtime/src/runtime.rs(version-scoped prefix, cleanup under the install lock, end-to-end regression test),crates/vp_js_runtime/src/lib.rs(export),crates/vp_global_cli/src/commands/env/clean.rs(sweep + reporting), and a new snapshot fixture caseenv_clean_interrupted_download_staging.Regression tests: unit tests for same-version-only install cleanup (current + legacy formats), lock-protected clean sweep (a staging dir whose lock is held survives and is removed once free), legacy attribution, an end-to-end download test with pre-seeded leftovers, a
try_lock_exclusivetest, and the CLI snapshot recording✓ Removed 2 interrupted downloadswith the surviving empty leftover.Validation:
cargo test -p vp_js_runtime— 147 passed (incl. the real-network integration download test);cargo test -p vp_shared -p vp_global_cli— 577 + 151 passed.cargo check --workspace --all-features --all-targets --locked, thejust lintclippy command, andcargo fmt --all --check— all clean; no lockfile change.just snapshot-test-global env_clean— all 3 cases pass; existing snapshots byte-identical.VP_HOMEagainst the throttled mirror: SIGTERM mid-download → one.tmp-node-24.22.1-…leftover (the unavoidable one); second SIGTERM attempt → still only one leftover (previously they accumulated); completed install → zero.tmp*dirs;vp env clean noderemoved 4 seeded legacy leftovers ("✓ Removed 4 interrupted downloads") and kept the unattributable empty one;vp env clean nodeduring a live install left the live staging dir untouched and the install completed successfully; control case (uninterrupted install) → no leftovers.This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.
I've opened a pull request with this fix: #3627
fix(env): resume interrupted Node.js downloads instead of leaking sta…