rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Thousands of conhost.exe and rg.exe processes are started upon opening a project leading to a crash

Open ArmoredPony opened this issue 1 year ago • 9 comments

rust-analyzer version: v0.3.2146

rustc version: 1.82.0

editor or extension: VSCode

When a project is opened, VSCode begins to build it, spawns thousands of conhost.exe and rg.exe processes, until it (hopefully) crashes with 'Out Of Memory' error. Sometimes, it takes down some of the other processes with it (it killed task manager on my Windows machine once). Sometimes, it kills X11 server on my Linux machine. Sometimes, it freezes the whole system, forcing me to reboot. I'm not kidding, I saw process counter go higher than 10000. You have to take my word on that because at this point both Windows and Linux usually become unresponsive, but this screenshot from Windows Task Manager demonstrates the issue with 2k processes running. Image Most of them are conhost.exe and rg.exe and their number only goes higher.

Here's a project I'm talking about https://github.com/cptpiepmatz/nu-jupyter-kernel. Although, it looks like it can be any project with a big number of dependencies. To reproduce the issue, clone the repo and open the folder in VSCode.

I tried to look at logs in the 'Output' panel in VSCode but either the extension doesn't print anything in it, or VSCode cannot render it before crashing. Activity bar at the bottom of the screen says something about building proc macros.

If a project is built before being opened in VS Code, no crash happens. VSCode still spawns a lot of processes, but their number usually does not go above 150, and after a while those processes are closed and RAM and CPU consumption is back to normal.

This issue manifests under the same conditions on Windows 10 and Linux Mint 22. It also happens to be the same on pre-release version of the extension.

I would love to provide any additional information I can if it helps to solve the issue.

ArmoredPony avatar Oct 20 '24 21:10 ArmoredPony

AFAIK, rust-analyzer doesn't run either rg or conhost.

Based on the fact that your project seems to be related to nushell (which does run conhost...) the fact that this occurs during the "building proc macros" step, and the fact that it doesn't happen when the project has already been built, it sounds like this problem is caused by your project:

Your project or one of it's dependencies is using a procedural macro which is spawning all of these processes. To avoid the problem you'd need to find this procedural macro and fix it.

Diggsey avatar Oct 20 '24 22:10 Diggsey

Then shouldn't the same thing happen if I run cargo check or cargo build from terminal without opening VSCode?

ArmoredPony avatar Oct 21 '24 08:10 ArmoredPony

cargo check --all-targets

lnicola avatar Oct 21 '24 08:10 lnicola

rust-analyzer does some RUSTC_WRAPPER shenanigans that might be breaking depending on what the build scripts are doing here

Veykril avatar Oct 21 '24 08:10 Veykril

cargo check --all-targets

I ran this in terminal too, had no problems whatsoever

ArmoredPony avatar Oct 21 '24 09:10 ArmoredPony

One thing you could check is whether setting rust-analyzer.cargo.buildScripts.useRustcWrapper to false fixes this behavior. Either way it would be good to find which build scripts / proc-macro is spawning these processes to figure out the problematic interaction here

Veykril avatar Oct 21 '24 10:10 Veykril

One thing you could check is whether setting rust-analyzer.cargo.buildScripts.useRustcWrapper to false fixes this behavior.

Tried that and it didn't help, VSCode crashed after creating 4k processes. It feels that there are less processes created per second with this option disabled, but it is hard to tell since this number always fluctuates and task manager quickly starts lagging.

I'd like to help you find the problematic dependency but I'm not sure how to do that without manually looking through each crate and its sub-dependency.

I also have noticed that if VSCode crashes or even if the system becomes completely frozen and I'm forced to hard-reboot it, upon opening the project, this issue does not reappear. As if the project was built and it is cleanup that went wrong.

ArmoredPony avatar Oct 21 '24 10:10 ArmoredPony

I couldn't find any reference to rg in your dependency tree. Pretty strange.

lnicola avatar Oct 21 '24 16:10 lnicola

Have you disabled all other plugins in vscode?

mohe2015 avatar Oct 21 '24 20:10 mohe2015

Issue is unclear and requires more information by OP, so closing

Veykril avatar Jun 17 '25 07:06 Veykril

yeah sorry, a few months after this issue was opened the problem suddenly disappeared. no idea what exactly has changed, but these processes are no longer there. this issue should've been marked as closed

ArmoredPony avatar Jun 22 '25 12:06 ArmoredPony

@Veykril

Hi, I'd like to reopen this issue because it is still happening on the latest versions of VS Code + rust-analyzer on Windows.

Even with:

  • cachePriming disabled
  • procMacro disabled
  • buildScripts disabled
  • allTargets = false
  • check.allTargets = false
  • aggressive directory excludes (target, node_modules, .git)

rust-analyzer still spawns hundreds of rg.exe and conhost.exe processes as soon as a Rust project is opened. This happens only when the extension is enabled. Disabling rust-analyzer (workspace only) instantly stops the problem entirely.

This is not related to Cargo tasks or manual searches. It is rust-analyzer triggering ripgrep subprocesses in a loop.

Additional notes:

  • Running cargo check before opening the project does NOT prevent t

he behavior.

  • The processes appear and respawn faster than they can be killed.
  • The only workaround is disabling rust-analyzer for the workspace.

This matches exactly what the original reporter described.
The bug is still present and affects multiple users.

Please consider reopening the issue so it can be properly tracked.

Image

G4sp4rCS avatar Nov 16 '25 20:11 G4sp4rCS

As explained previously, r-a does not spawn any rg or conhost process. This blame is likely on a faulty build script and not on r-a. Unless there is a reproducible example, I don't think this issue should be reopened.

ChayimFriedman2 avatar Nov 16 '25 20:11 ChayimFriedman2

@G4sp4rCS Have you tried opening an empty rust project? (cargo new --bin test)

mohe2015 avatar Nov 16 '25 21:11 mohe2015

@G4sp4rCS I later found out that in my case it was this https://github.com/microsoft/vscode/issues/218666. I clearly remember disabling all other plugins when reproducing this problem, but I guess I somehow failed to do the job back then

ArmoredPony avatar Nov 17 '25 15:11 ArmoredPony