Skip to content

Comments

fix: ensure temporary caches remain until process completion#15977

Open
monosans wants to merge 3 commits intoastral-sh:mainfrom
monosans:patch-1
Open

fix: ensure temporary caches remain until process completion#15977
monosans wants to merge 3 commits intoastral-sh:mainfrom
monosans:patch-1

Conversation

@monosans
Copy link

Fixes #15967

Comment on lines 389 to 395
// Unblock cache removal operations for persistent caches. If the cache is temporary
// (used when `--no-cache` was requested), we must keep it alive until the child
// process has been spawned and finished; otherwise the temporary directory will be
// deleted and the child's executable may not be present on disk.
if !cache.is_temporary() {
drop(cache);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, we still to drop (or more specifically, unlock) the locked file, while keeping the temp directory around

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to unlock it if we're the only one operating on it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep it locked, it means that every uv run blocks any uv cache operation until it's done, this would be the strictest setting but we have talked in another thread about that we don't actually want to block parallel operations on the cache where possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least with --link-mode reflink|hardlink, I see no risk for the spawned process being affected by cache cleaning

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is specifically with --no-cache in which a temporary dedicated cache is being used?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I don't think that keeping the (temporary) cache locked would block any other operations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is specifically for --no-cache, then I don't see why it's a problem to leave it locked.

@monosans monosans requested a review from konstin September 22, 2025 14:16
args.iter().map(|arg| arg.to_string_lossy()).join(" ")
);

// Unblock cache removal operations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need this same change in the project run command per #15989

zanieb added a commit that referenced this pull request Sep 22, 2025
…15990)

We're seeing reports of a regression from
#15888 where `--no-cache` causes `uv
run` and `uvx` to fail to spawn a command.

The intent of this code was to allow destructive cache operations
_after_ we'd finished setting up the environment. However, it's unclear
to me that it's safe to run `uv cache clean` during a `uv run` operation
(e.g., `uv run --script` uses an environment in the cache) and, more
importantly, we cannot drop non-persistent caches (e.g., from
`--no-cache`) as they include the environment we're spawning the command
in.

Alternative to #15977 which retains release of the lock — we may want to
consider that approach still but this regression needs to be resolved
quickly.

Closes #15989
Closes #15987
Closes #15967
@zanieb
Copy link
Member

zanieb commented Sep 22, 2025

I just removed these drop statements entirely in #15990 but we can consider releasing the lock for cases where the cache is not used in uv run. We can't just handle temporary caches though, e.g., uv cache clean during a concurrent uv run --script would delete the script environment. I'm not sure what's best.

@konstin
Copy link
Member

konstin commented Sep 23, 2025

We should add the test case either way, the cache logic we can tune based on how much we care about uv cache commands not being blocked.

@konstin
Copy link
Member

konstin commented Oct 6, 2025

I just removed these drop statements entirely in #15990 but we can consider releasing the lock for cases where the cache is not used in uv run. We can't just handle temporary caches though, e.g., uv cache clean during a concurrent uv run --script would delete the script environment. I'm not sure what's best.

Are there any cases we don't want to release the locks with uv run, given the problems in astral-sh/setup-uv#588?

@zanieb
Copy link
Member

zanieb commented Oct 6, 2025

Yeah I already gave an example there: uv run --script is not concurrency-safe with uv cache clean if you release the lock.

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.

The command is not in PATH if --no-cache is used in uv tool run

4 participants