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

feat(scanner): add option not to follow symlinks #5325

Merged
merged 1 commit into from Nov 2, 2023

Conversation

lutzky
Copy link
Contributor

@lutzky lutzky commented Jul 18, 2023

Never consider a symlink to be a subdirectory; this prevents hanging when the symlink points to a slow/inaccessible filesystem.

Description

Instead of using is_dir, which follows symlinks, use symlink_metadata, which doesn't.

Motivation and Context

If the current directory has a symlink to a slow filesystem (e.g. an inaccessible network filesystem), is_dir hangs indefinitely, disregarding scan_timeout.

This should help with some instances of #312.

Screenshots (if appropriate):

n/a

How Has This Been Tested?

  • I have tested using MacOS
  • I have tested using Linux
  • I have tested using Windows

I've tested by running starship timings with network disconnected in a directory which includes a symlink to a network filesystem. Without my change it hangs, with my change it doesn't.

Checklist:

  • I have updated the documentation accordingly
  • I have updated the tests accordingly

@lutzky lutzky marked this pull request as ready for review July 18, 2023 22:28
@andytom andytom changed the title fix: Fix hang on symlinks to inaccessible filesystems fix: stop hanging on symlinks to inaccessible filesystems Jul 19, 2023
@davidkna
Copy link
Member

Following symlinks does seem somewhat useful, I assume there is no option to ignore cross-device symlinks only?

@lutzky
Copy link
Contributor Author

lutzky commented Jul 27, 2023

The trick is determining whether or not a symlink is cross-device without calling stat on the destination (because that's the bit that might fail). https://github.com/stemjail/mnt-rs seems to be able to do it, but doesn't appear very portable. WDYT?

@davidkna
Copy link
Member

The trick is determining whether or not a symlink is cross-device without calling stat on the destination (because that's the bit that might fail). https://github.com/stemjail/mnt-rs seems to be able to do it, but doesn't appear very portable. WDYT?

Try using systemstat which we already depend on, relevant functions will likely return an error on unsupported operating systems which should be handled.

@lutzky
Copy link
Contributor Author

lutzky commented Jul 28, 2023

I've tried out some stuff in a99335a; WDYT? Reasonable or too brittle?

@lutzky
Copy link
Contributor Author

lutzky commented Jul 28, 2023

There's an issue with systemstat: mounts proceeds to immediately stat each filesystem, causing it to wait on network. 😞

I guess one path forward is submitting a patch to systemstat to make a no-stat-just-the-files option... WDYT?

@davidkna
Copy link
Member

I guess one path forward is submitting a patch to systemstat to make a no-stat-just-the-files option... WDYT?

The crate is somewhat minimalistic, so I'm uncertain if the maintainers will be receptive to such a change.

@lutzky
Copy link
Contributor Author

lutzky commented Aug 14, 2023

So, given these limitations, how about we go back to the "don't follow symlinks in this case" option? Perhaps as a configurable?

@davidkna
Copy link
Member

I think making it configurable is fine, unless you want to try making the timeout itself more reliable.

@lutzky lutzky force-pushed the master branch 3 times, most recently from 02f298a to dbd0d87 Compare August 15, 2023 21:19
@lutzky
Copy link
Contributor Author

lutzky commented Aug 15, 2023

Making the timeout itself more reliable is more challenging (D is called "uninterruptable" for a reason, you'd end up accumulating stale threads, it might be worth doing but would be messy). For now, I've made it configurable. PTAL

@lutzky
Copy link
Contributor Author

lutzky commented Sep 18, 2023

Finally added tests. The failures on nightly are unrelated to my changes, occur on master as well, and should be fixed by time-rs/time#622. Do my changes seem OK now?

Copy link
Member

@davidkna davidkna left a comment

Choose a reason for hiding this comment

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

LGTM

Settings this to false can fix hanging on symlinks to slow/inaccessible
filesystems.
@lutzky
Copy link
Contributor Author

lutzky commented Oct 22, 2023

Still blocked on #5532 for passing the checks.

@davidkna davidkna changed the title fix: stop hanging on symlinks to inaccessible filesystems feat(scanner): add option not to follow symlinks Nov 2, 2023
@davidkna davidkna merged commit 7b851fc into starship:master Nov 2, 2023
17 of 20 checks passed
@davidkna
Copy link
Member

davidkna commented Nov 2, 2023

Thanks for the contribution @lutzky!

lutzky added a commit to lutzky/dotfiles that referenced this pull request Nov 3, 2023
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.

None yet

2 participants