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

fix: detect infinite file system loop and bail out #15141

Closed
wants to merge 3 commits into from

Conversation

weihanglo
Copy link
Member

What does this PR try to resolve?

For #9528 if the loop in inside /sys/block it would be an infinite loop.
In that case Cargo is better bailing out instead of emitting endless warnings.
We set a relatively large limit 1024
to ensure there is any legitimate reason to have file system loop.

This also turn the file system loop warning into a debug! log, per #12600 request.

How should we test and review this PR?

I don't really know if 1024 is really a big enough number.
My naive instinct told me that there is no a valid use case for so many loops in a Cargo package.

Additional information

Fixes #12600

File system loops are pretty common on Unix platforms.
This is a preparation for the next fix to show the behavior change.
For rust-lang#9528 if the loop in inside `/sys/block` it would be an infinite
loop. In that case Cargo is better bailing out instead of emitting
endless warnings. We set a relativelly large limit to ensure there is
any legitimate reason to have file system loop.
@rustbot
Copy link
Collaborator

rustbot commented Feb 4, 2025

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 4, 2025
@weihanglo weihanglo changed the title fix: detect file system loop limit and bail out fix: detect infinite file system loop limit and bail out Feb 4, 2025
@weihanglo weihanglo changed the title fix: detect infinite file system loop limit and bail out fix: detect infinite file system loop and bail out Feb 4, 2025
Copy link
Contributor

@epage epage left a comment

Choose a reason for hiding this comment

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

For myself, I'd like to better understand more about the use case before moving forward.

@rustbot rustbot added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 4, 2025
@weihanglo
Copy link
Member Author

For myself, I'd like to better understand more about the use case before moving forward.

While this is a fix of #12600, it is also a solution to #9528 (comment). Fixing #12600 is more like a side effect.

The warning of file system loop was a solution to let people know they are stuck in infinite loop (#9528). However endless warnings are not particularly useful. Especially if it happens in CI and then users need to wait for CI service timing out, which could be hours. Breaking the loop is more pragmatic than that I believe.

@ijackson
Copy link
Contributor

ijackson commented Feb 4, 2025

By "bail out" I hope we mean "skip the recursion and continue scanning other files" rather than "fai".

Currently I'm getting these warnings but I just want them suppressed, not to become fatal. See #12600

@weihanglo
Copy link
Member Author

@ijackson

We set a relatively large limit 1024
to ensure there is any legitimate reason to have file system loop.

Unsure whether 1024 is large enough to say that you have an “infinite file system loop”. Can increase it if you have a use case that loops back to the same directory more than 1024 times.

@ijackson
Copy link
Contributor

ijackson commented Feb 4, 2025

@ijackson

We set a relatively large limit 1024
to ensure there is any legitimate reason to have file system loop.

Unsure whether 1024 is large enough to say that you have an “infinite file system loop”. Can increase it if you have a use case that loops back to the same directory more than 1024 times.

I'm not sure I follow. In one of my use cases I have, for example, a symlink maint -> .

Every time you try to follow it, it will come back to the same directory.

Currently I'm getting a warning about this, but cargo seems to function. If this warning becomes an error my project will become unbuildable.

The value of 1024 doesn't seem relevant.

(edited to clarify formatting)

@epage
Copy link
Contributor

epage commented Feb 4, 2025

From my reading of the code and walkdir, the 1024 is more of a "if you find 1024 unique symlinks pointing to an ancestor, bail". Putting a cap on that seems like an odd solution.

That was the solution proposed in #9528 (comment) but that comment is overall light on details and solution seems more focused on "error rather than make my CI slow" which seems like a false dichotomy and that we should explore other solutions. As that person didn't create an issue, should we continue that conversation over at #12600 (as our PRs are generally more focused on the implementation than problem/solution discussions)?

@weihanglo
Copy link
Member Author

From my reading of the code and walkdir, the 1024 is more of a "if you find 1024 unique symlinks pointing to an ancestor, bail". Putting a cap on that seems like an odd solution.

Agree that it is just a random cap. #12235 is probably one solution to it. Let's close this PR and discuss in #12600 then.

@weihanglo weihanglo closed this Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

warning: File system loop found: xxx printed when running cargo run on file not ever needed by cargo
4 participants