Skip to content

fix(toolchain): stop the PATH fallback from re-running the proxy itself - #5295

Open
harshitsaini17 wants to merge 2 commits into
rust-lang:mainfrom
harshitsaini17:fix/4355-detect-proxy-self-recursion
Open

harshitsaini17 wants to merge 2 commits into
rust-lang:mainfrom
harshitsaini17:fix/4355-detect-proxy-self-recursion

Conversation

@harshitsaini17

Copy link
Copy Markdown

Fixes #4355

When a tool like rustfmt is missing from the toolchain, rustup falls back to the one on PATH and it run itself repeatedly untill recursion limit exhuasted and then show error.

Now, before falling back, rustup checks if the first match on PATH is the running rustup binary. If it is, it shows the error right away. This is the first idea ChrisDenton suggested in the issue, and PATH is not changed.

Before: 21 runs, about 350 ms. After: 1 run, about 19 ms. The error message is the same.

I added a test that counts the runs (3 on main, 1 with the fix). A real rustfmt earlier on PATH still runs as before. cargo fmt, cargo clippy and cargo test --features test pass. I am using Arch linux, so, I havent tested on Windows.

When a tool is missing from the toolchain, the proxy runs the bare name
from PATH, which is usually the same proxy again. Check if the first
match on PATH is the running executable and report the missing tool
right away, instead of after hitting the recursion limit.

Fixes rust-lang#4355.
Copilot AI balanced review requested due to automatic review settings December 3, 2026 14:47
@rustbot

rustbot commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Welcome, and thank you for contributing to rustup! A reviewer will take a look at your PR, typically within a week or two.

Please see the contribution instructions and our LLM policy for more information.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@rami3l
rami3l self-requested a review December 3, 2026 16:38
Comment thread src/toolchain.rs Outdated
Comment on lines +487 to +490
env::split_paths(&path)
.map(|dir| dir.join(binary))
.find(|candidate| candidate.is_file())
.is_some_and(|candidate| is_same_file(&me, &candidate).unwrap_or(false))

@djc djc Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this map().find().is_some_and(|_| _.unwrap_or()) contraption is not easy enough to understand.

Also I think this function should be detached from Toolchain since it only reads from process as far as I can see, and it should be defined its calling function.

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I learned something good here. I changed it to a plain loop and moved it out of Toolchain as a free function below create_command. I havent squashed the commits yet, so the change is easy for you to see. I will squash once you're done reviewing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trying to use a component that is not installed runs for about a second before reporting an error

4 participants