-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Cargo should say which lock it waits on when run with --verbose
#15094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Shouldn't the lock be automatically released when the process dies and the OS cleans up the fd? |
That would be a reasonable assumption, however it seems like this time it did not happen. I don't really have any knowledge on why it might have not been cleaned up. But it did happen with both cargo and bootstrap at the same time, so I assume something went wrong. There is also this stack overflow question: https://stackoverflow.com/questions/47565203/cargo-build-hangs-with-blocking-waiting-for-file-lock-on-the-registry-index-a, where some people recommend deleting the file or say that it helped them. So I'd assume there are cases where the OS does not do the cleanup... |
@Gordon01 provided an implementation for this in #15486. @weihanglo commented:
|
For me, this is too low level of a detail to be shown by default. I do wonder what should be our bar for |
I agree. Without prior knowledge its hard to discover.
Yes, but in 99,9% it's a garbage cluttering the output which is definitely a bad UX.
Agree. The only good idea I have is to print path after some delay (say 5 seconds). |
I would love to see something like this, with some more details like who is holding the lock. |
I've discovered that lock files are currently empty. I propose saving a process ID inside, possibly with an acquisition timestamp. A PID alone would be sufficient to easily determine if a process is still running. While waiting for a lock, I could periodically print a status like Another option would be to also save a timestamp. In this case, the file should be structured as JSON (or TOML), for example: { "pid": 12345, "timestamp": "2025-05-13T22:00:00Z" } The status message could then display:
My plan is to write metadata in Currently, pub fn open_rw_exclusive_create<P>(
&self,
path: P,
gctx: &GlobalContext,
msg: &str,
) -> CargoResult<FileLock>
where
P: AsRef<Path>,
{
let mut opts = OpenOptions::new();
opts.read(true).write(true).create(true);
let mut lock = self.open(path.as_ref(), &opts, true)?;
acquire(
gctx,
msg,
lock.path(),
&|| try_lock_exclusive(lock.file()),
&|| lock_exclusive(lock.file()),
)?;
// Write PID/timestamp after acquiring the lock
let _ = lock.write_metadata();
Ok(lock)
} Open Questions
|
Attaching some extra data sounds good. I know that PostgreSQL does that in the
It varies. Also depends on how focused people can be these day 😆. I would love to try like 15s to start with, but I don't really now.
I would recommend JSON so we have room to expand it in the future. Also easy to parse without needing to look at any bespoke format.
We could clean up the content before unlock, though as it is advisory only it is fine as well if we don't want to. |
Problem
Due to an unfortunate series of events (rust-analyzer OOM'ing after using >44GiB of RAM) I had
cargo
's package cache permanently locked. When I'd try to build something all I would see is this:(I had no cargo/r-a running at that point)
This is only semi-helpful -- it shows you what's the problem, but not how to fix it.
Proposed Solution
It would be nice if
cargo
would print the path to the lockfile. In this case that would be something like~/.cargo/.package-cache
and~/.cargo/.package-cache-mutate
(deleting those fixed the problem for me). It's probably better to only print those with--verbose
, since usually you are actually waiting for anothercargo
process.Notes
Upd: this can be even worse for other locks/in combination with other build systems.
Just not I had to figure out that the blocking/broken lock is actually
.../rust-q/build/rust-analyzer/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu/release/.cargo-lock
.The text was updated successfully, but these errors were encountered: