rust-analyzer: Server gets stuck, apparently due to broken Cargo metadata
So I’ve run an issue a few times now over the last few weeks where my cargo check commands in the terminal get stuck for a very long time (sometimes minutes) blocking on “waiting for file lock on package cache”. I just had this happen to me again, and decided to dig in a little. I now think this might be happening when RA tries to read my Cargo.toml file just as I’m editing it. This gets it into an error state, like this:
[ERROR rust_analyzer::reload] failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /Users/djc/src/ids-rs/Cargo.toml, cargo 1.47.0 (f3c7e066a 2020-08-28): Failed to run `cargo metadata --manifest-path /Users/djc/src/ids-rs/Cargo.toml`: Error during execution of `cargo metadata`: error: failed to parse manifest at `/Users/djc/src/ids-rs/nominl/Cargo.toml`
Caused by:
could not parse input as TOML
Caused by:
newline in string found at line 24 column 96
[ERROR flycheck] Flycheck failed to run the following command: "cargo" "check" "--workspace" "--message-format=json" "--manifest-path" "/Users/djc/src/ids-rs/Cargo.toml" "--all-targets" "--all-features"
[ERROR rust_analyzer::main_loop] cargo check failed: Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(ExitStatus(25856)))
After this, it looks like it eventually recover, but it’s taking very long to do so (maybe some timeout?) – and all the while it appears to be holding the package cache file lock.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 17
- Comments: 17 (7 by maintainers)
Btw I believe I finally fixed this by running
rustup updateAha, the issue is that it’s trying to use
pythonbut I only havepython3:I think this is an issue on x.py’s end since its shebang requests
pythonbut that may not exist on newer computers. Indeed, if I run./x.py check, I getenv: python: No such file or directory. I noticed this earlier but didn’t connect the dots to the r-a issue. I’ll ask T-compiler about this. Thanks!EDIT: It turns out that there’s already an issue for this: https://github.com/rust-lang/rust/issues/71818. The issue with r-a can be circumvented with this: https://github.com/rust-lang/rustc-dev-guide/pull/1335
@bluretrece It turns out that there’s a command that gets blocked by a request for user info. It’s a cargo subcommand. I’ll look it up in my history and post.
Looks like you set your
rust-analyzer.checkOnSave.commandto an empty string