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

Avoid infinite loop in case where pwd returns relative path #525

Conversation

yyuu
Copy link
Contributor

@yyuu yyuu commented Jan 3, 2014

The pwd may return relative path if the $PWD is badly declared in bash/zsh (e.g. PWD="." bash). To avoid the infinite loop in find_local_version_file(), stop finding the version file if the target paths are same consecutively.

The `pwd` may return relative path if the `$PWD` is badly declared
in bash/zsh (e.g. `PWD="." bash`). To avoid the infinite loop in
`find_local_version_file()`, stop finding the version file if the
target paths are same consecutively.
@yyuu
Copy link
Contributor Author

yyuu commented Jan 3, 2014

Sorry, I confiemd this doesn't work expectedly. Now I'm working to fix this, and will update issue if fixed.

@yyuu
Copy link
Contributor Author

yyuu commented Jan 3, 2014

I've done fixing.

I couldn't get the absolute path of pwd reliably in case of pwd returns a relative path. Using readlink -f allow me to implement the feature, but it is unacceptable because it is not working on BSD/OSX platform.

The current patch will just preserve the value of $root over loops, and stop if the consecutive values are same. This avoids the infinite loop in find_local_version_file() even if the pwd returns a relative path.

@mislav
Copy link
Member

mislav commented Jan 3, 2014

Fix looks good, but:

  1. Who/what would set PWD="."?
  2. Couldn't we simply check if the value of $root contains any slashes, and abort the loop if not? Because if it doesn't contain any slashes, then root="${root%/*}" is a no-op.

@yyuu
Copy link
Contributor Author

yyuu commented Jan 6, 2014

To tell the truth, I have ran into this with pyenv and the golang toolchain, not with rbenv. Because the golang toolchain sets PWD=. when invoking go get (get source of libraries from external repositories), hg was stalled by infinite loop in pyenv if there is mercurial installed in pyenv.

I have already added a workaround for this in pyenv. I think this should also be fixed in rbenv since there is possibility to reproduce same issue in rbenv.

@mislav
Copy link
Member

mislav commented Jan 6, 2014

I like the simpler check but I'm still not sure whether this is an issue that needs fixing. Generally I'm uncomfortable by tools that set PWD manually since I don't see a reason for it. But in order to pull it in rbenv, I would definitely like a test that reproduces the issue.

@sdm7g
Copy link

sdm7g commented May 28, 2014

I don't know if this is the same bug or issue, but I've been having problems with an infinite loop in rbenv when using the system ruby on Mac OSX (Mavericks). Everything initially seems to work. But if I open a 2nd terminal window in the same rails directory, rails and rake will both loop in the 2nd window, while still working properly in the first. They are both repeatedly calling rbenv-which. I don't see this problem with other rails projects that are not using the system ruby and rails. Running "$(rbenv which rails) server" or "./bin/rails server" directly works OK.

@mislav
Copy link
Member

mislav commented May 29, 2014

@sdm7g That definitely sounds weird. Does anything set PWD in your environment? Can you set export RBENV_DEBUG=1 in your 2nd terminal window to detect why the loop happens?

@sdm7g
Copy link

sdm7g commented May 30, 2014

On May 28, 2014, at 11:18 PM, Mislav Marohnić notifications@github.com wrote:

@sdm7g That definitely sounds weird. Does anything set PWD in your environment? Can you set export RBENV_DEBUG=1 in your 2nd terminal window to detect why the loop happens?


Reply to this email directly or view it on GitHub.

My theory about when it goes wrong seems to be wrong : it now hangs in a loop in every instance.
I was hoping to do a DEBUG dump of a properly working version so I could compare the two cases.

I have only the dump of the non-working, looping instance, and I haven’t
yet been able to decipher it well enough to figure out where it goes wrong.

[ Here it is enclosed below. ]

— Steve Majewski

@mislav
Copy link
Member

mislav commented May 31, 2014

If you have some RBENV_DEBUG output, please paste it in a Gist or something, then link here. Thanks

@mislav
Copy link
Member

mislav commented Sep 25, 2022

Closing due to this being stale. I haven't heard reports of this affecting anyone else in the wild.

@mislav mislav closed this Sep 25, 2022
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

3 participants