Skip to content
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

Server gets stuck, apparently due to broken Cargo metadata #6589

Closed
djc opened this issue Nov 19, 2020 · 17 comments
Closed

Server gets stuck, apparently due to broken Cargo metadata #6589

djc opened this issue Nov 19, 2020 · 17 comments
Labels
C-support Category: support questions S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@djc
Copy link

djc commented Nov 19, 2020

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.

@lnicola lnicola added the S-actionable Someone could pick this issue up and work on it right now label Dec 21, 2020
@mathemaphysics
Copy link

Same thing happening to me. Doesn't matter what I do it just blocks saying that it's waiting for cargo metadata or cargo check. Closing all files doesn't do anything.

@luisvgs
Copy link

luisvgs commented Dec 3, 2021

@mathemaphysics I'm currently dealing with the same issue. Did you were able to solve it?

@mathemaphysics
Copy link

@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.

@luisvgs
Copy link

luisvgs commented Dec 3, 2021

@mathemaphysics please, I'd appreciate it a lot! rust-analyzer is still getting stuck in all of my projects. I opened an issue describing the bug last night, but still got no responses whatsoever.

@chrisguida
Copy link

I am also getting this error, disabling, uninstalling, reinstalling, etc do not help

@clarammdantas
Copy link

I am also getting this error and also tried to disabling, uninstalling, reinstalling, and all of that. It didn't solve the problem

@Veykril Veykril added S-unactionable Issue requires feedback, design decisions or is blocked on other work and removed S-actionable Someone could pick this issue up and work on it right now labels Jan 11, 2022
@Veykril
Copy link
Member

Veykril commented Jan 11, 2022

We need a reproduction here to be able to work on this.

@chrisguida
Copy link

Btw I believe I finally fixed this by running rustup update

@clarammdantas
Copy link

I finally found a solution that worked for me, and what did the trick was to open the project with a root as the rust project I'm working on. Before I opened two directories up because the rust project is part of a large mono repo project.

@flipbit03
Copy link
Contributor

flipbit03 commented Apr 3, 2022

To whoever is losing hours of debugging time puzzled about this:

I struggled too and saw some threads which spanned for months where people were lost. I too lost a couple of hours on this stupid thing.

Turns out, the only problem is that cargo clippy was not available. All you need to do to make this go away is to add cargo clippy to your environment via:

rustup component add clippy

This is not a problem technically related to rust-analyzer. But from an user experience standpoint, rust-analyzer expects cargo clippy to be available. I think it would be better if it could display an informative message or hint after cargo's error mesage. Something along the lines of :

cargo check failed: Cargo watcher failed, the command produced
no valid metadata (exit code: ExitStatus(unix_wait_status(256))).
Do you have "cargo clippy" installed?

This would save unadvised users hours of grief.

In my personal case, I was having the same problem with a project that uses a Devcontainer. So with Devcontainers, you have a Dockerfile that defines your environment and you develop from inside it...

I decided to base my Devcontainer off rust:1.XX-bullseye instead of using the one that Microsoft provides as a ready-to-use one, mainly because I like to learn the internals and am not comfortable depending on a magical turnkey solution .

Thanks in advance, and hope this answer can be useful to someone.

@flodiebold flodiebold added the C-support Category: support questions label Apr 3, 2022
bors bot added a commit that referenced this issue Apr 5, 2022
11891: Better error message on Flycheck Error message (from: unactionable error message if we are using `clippy` as the checker) r=Veykril a=flipbit03

I have commented on this [S-unactionable issue](#6589) that the Flycheck error message should maybe provide a hint about what tool it actually runs. Searching on some places on the Internet I've found multiple people, including myself, losing copious amounts of time on the same issue. So I've decided to make this very small PR :-)

From an user experience standpoint, the current error message is unhelpful to the end user, because the end user does not know exactly what it needs to check/fix (outdated, broken, or missing `cargo clippy`). In my own case, `cargo clippy` was actually missing altogether (developing off `rust:1.59.0-bullseye` official Docker image).

Thanks in advance!




Co-authored-by: Cadu <cadu.coelho@gmail.com>
@camelid
Copy link
Member

camelid commented Apr 7, 2022

I'm running into a similar error while working on rustc itself. I tried deleting the build cache, restarting the r-a server, and restarting VS Code, without success. Formatting is working, but this error message keeps appearing:

cargo check failed: Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(unix_wait_status(32512)))

and no errors are being displayed in the UI (even though my code is incorrect). x.py check works fine.

I have clippy installed for all toolchains via rustfmt (though I guess not the custom toolchain used by x.py).

Note that go-to-def, find refs, and type inlays are all working.

@Veykril
Copy link
Member

Veykril commented Apr 7, 2022

Can you try the nightly version of r-a? That one should show you the actual error message

@camelid
Copy link
Member

camelid commented Apr 7, 2022

Aha, the issue is that it's trying to use python but I only have python3:

cargo check failed: Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(unix_wait_status(32512))) Cargo's stderr output: env: python: No such file or directory

I think this is an issue on x.py's end since its shebang requests python but that may not exist on newer computers. Indeed, if I run ./x.py check, I get env: 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: rust-lang/rust#71818. The issue with r-a can be circumvented with this: rust-lang/rustc-dev-guide#1335

@lattice0
Copy link

lattice0 commented Apr 9, 2022

neither rustup component add clippy or rustup update fixed for me

@Veykril
Copy link
Member

Veykril commented Apr 9, 2022

Can you also try the nightly version of r-a? That one should show you the actual error message.

There isn't much we can do here without a reproduction otherwise. I'll go ahead and close this issue as there is not much we can do, and we improved the error output for most cases.
If you run into this and the extra error output from current nightly (or next week's stable) is unhelpful you can open a new issue with sufficient info for us.

@Veykril Veykril closed this as completed Apr 9, 2022
@lattice0
Copy link

lattice0 commented Apr 9, 2022

On pre-release I got

cargo check failed: Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(unix_wait_status(25856)))
Cargo's stderr output:
error: no such subcommand: ``

	Did you mean `b`?

and on VSCode output:
[ERROR flycheck] Flycheck failed to run the following command: "cargo" "" "--workspace" "--message-format=json" "--manifest-path" "/home/dev/orwell/Cargo.toml" "--all-targets"

Looks like on of the subcommands is ""

@Veykril
Copy link
Member

Veykril commented Apr 9, 2022

Looks like you set your rust-analyzer.checkOnSave.command to an empty string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-support Category: support questions S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests