fix(clean): keep cleaning when cache files are locked and report holders#34946
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Windows an open file cannot be deleted, which means
deno cleanwouldabort 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 cleanfrom 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 whichprocess(es) currently hold the locked files open. Each holder's image path is
resolved via
QueryFullProcessImageNameW, and holders that are adenoexecutable 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