18

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.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
sullyh7
  • 225
  • 1
  • 2
  • 6

1 Answers1

30

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.

  • Maybe setting `"rust-analyzer.cargo.autoreload":` to `false` can change the default VSCode behavior to stop auto-downloading the packages when u are on a slow internet connection. – behkod Jan 25 '23 at 12:50
  • 1
    I tried it and it works, however , there is a yellow warning on the `rust-analyzer` button at the left bottom of vscode. The analyzer seems to be working fine despite that visual warning. The packages are not downloaded automatically upon save, i don't know if that may disable other important features ... – Normand Espinoza Jan 25 '23 at 16:44