Search code examples
rustdependenciesrust-cargo

Blocking waiting for file lock on package cache when I added dependency to Cargo.toml file


I added a dependency to a rust project, then ran cargo run, this gave me this error:

"Blocking waiting for file lock on package cache"

I tried the solution I found online which was to delete the ~/.cargo/.package-cache file, however this has not worked for me. When I type commands like cargo run and cargo update I just get the same message. Now even when I go to another rust project with no dependencies, and try to run it, I get the same "Blocking waiting for file lock on package cache" message. I am on a M1 MacBook Pro.


Solution

  • I got the same problem. I am using Linux and this is how to solve it:

    1. Close VS Code so that the the rust-analyzer extension will not be able restart cargo, rust-analyzer or rustc.

    2. Use a resource monitoring tool (i use btop) and search for rust. Kill cargo, rust-analyzer and rustc. Click on the process and then press k then enter to kill them on by one.

    3. Try using cargo r again and it should work fine without displaying "Blocking waiting for file lock on package cache".

    I still do not know how to prevent VS Code from automatically starting the download of the packages. If you can block VS Code from auto download and instead download the packages manually when invoking cargo r, you can stop the process by pressing ctrl+c and thus stop the download if you have slow internet connection at that time for example.