Skip to content

fix(clean): keep cleaning when cache files are locked and report holders#34946

Merged
bartlomieju merged 2 commits into
mainfrom
fix/deno-clean-locked-files
Jun 6, 2026
Merged

fix(clean): keep cleaning when cache files are locked and report holders#34946
bartlomieju merged 2 commits into
mainfrom
fix/deno-clean-locked-files

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

On Windows an open file cannot be deleted, which means deno clean would
abort partway through with a file-locking error whenever another Deno process
held one of the cache databases open. The most common trigger is the Deno
language server spawned by the VS Code extension: it eagerly opens the SQLite
caches under DENO_DIR (dep_analysis_cache_v2, node_analysis_cache_v2,
and others) and keeps the handles open for its whole lifetime, so running
deno clean from the integrated terminal fails until the editor is closed.
The failure is intermittent because the language server only opens some of
those caches lazily, after it has analyzed dependencies. This does not occur
on Unix, where an open file can still be unlinked.

This makes the cleaner best-effort instead of fail-fast. Per-file and
per-directory removal errors are collected rather than propagated, so the rest
of the cache is still removed even when a few files are locked. After the walk
completes, a warning lists the files that could not be removed.

On Windows the warning is enriched using the Restart Manager API
(RmStartSession / RmRegisterResources / RmGetList) to resolve which
process(es) currently hold the locked files open. Each holder's image path is
resolved via QueryFullProcessImageNameW, and holders that are a deno
executable are called out as the likely cause (the language server running in
an editor), so the message tells the user exactly what to close. The lookup
runs only on the failure path and is gated to Windows; on other platforms the
helper returns an empty list and the generic message is shown.

Closes #33903

On Windows an open file cannot be deleted, so `deno clean` would abort with
a file-locking error whenever a running Deno process (most commonly the
language server spawned by the VS Code extension) held a cache database open.

Make the cleaner best-effort: file and directory removal failures are now
collected instead of aborting the walk, so the rest of the cache is still
removed. Afterwards, warn about the files that could not be removed. On
Windows, the Restart Manager is used to resolve which process(es) hold the
files open and the message points the user at a running Deno process.

Closes #33903
The Restart Manager (rstrtmgr.dll) is only used on the `deno clean`
locked-file failure path, so delay-load it to avoid impacting Windows
startup, and record it in the windows_delay_loaded_dlls snapshot.
@bartlomieju
bartlomieju merged commit a5b709e into main Jun 6, 2026
136 checks passed
@bartlomieju
bartlomieju deleted the fix/deno-clean-locked-files branch June 6, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deno clean CLI fails when also using Deno VS Code Ext

1 participant