rbenv: cannot rehash: /usr/local/var/rbenv/shims/.rbenv-shim exists #759

Closed
drew-kun opened this Issue Jul 24, 2015 · 8 comments

Comments

Projects
None yet
7 participants
@drew-kun

Hi! When trying to $ rbenv rehash getting:

rbenv: cannot rehash: /usr/local/var/rbenv/shims/.rbenv-shim exists

What does that mean?

@mislav

This comment has been minimized.

Show comment
Hide comment
@mislav

mislav Jul 24, 2015

Member

During the rehash process, rbenv writes out the temporary file .rbenv-shim to indicate that the rehash is in progress. Then, if a parallel rbenv rehash process tries to run at the same time, it will fail because the file already exists. This guards against race conditions in parallel rehashes.

It doesn't sound like you're running multiple rbenv rehash processes in parallel, though. It seems like .rbenv-shim file was never cleaned up after a rehash that ran earlier. That earlier process might have been killed prematurely and never cleaned up after itself.

Solution: remove the file and try again.

Member

mislav commented Jul 24, 2015

During the rehash process, rbenv writes out the temporary file .rbenv-shim to indicate that the rehash is in progress. Then, if a parallel rbenv rehash process tries to run at the same time, it will fail because the file already exists. This guards against race conditions in parallel rehashes.

It doesn't sound like you're running multiple rbenv rehash processes in parallel, though. It seems like .rbenv-shim file was never cleaned up after a rehash that ran earlier. That earlier process might have been killed prematurely and never cleaned up after itself.

Solution: remove the file and try again.

@igorshtopor

This comment has been minimized.

Show comment
Hide comment
@igorshtopor

igorshtopor Sep 10, 2015

@mislav

That earlier process might have been killed prematurely and never cleaned up after itself.

I'm wondering what can be the root cause for such scenario?

@mislav

That earlier process might have been killed prematurely and never cleaned up after itself.

I'm wondering what can be the root cause for such scenario?

@mislav

This comment has been minimized.

Show comment
Hide comment
@mislav

mislav Sep 10, 2015

Member

@shyjt I don't know! Maybe if you run rbenv rehash but Ctrl-C it before it finishes.

Member

mislav commented Sep 10, 2015

@shyjt I don't know! Maybe if you run rbenv rehash but Ctrl-C it before it finishes.

@drew-kun

This comment has been minimized.

Show comment
Hide comment
@drew-kun

drew-kun Sep 11, 2015

That was so weird - I've reinstalled the package and it didn't help… But when I've repeated the procedure after restart it solved this problem and never happened again…

That was so weird - I've reinstalled the package and it didn't help… But when I've repeated the procedure after restart it solved this problem and never happened again…

@mcmire mcmire referenced this issue in rbenv/rbenv-gem-rehash Sep 22, 2015

Open

post_install hook fails #15

@trejkaz

This comment has been minimized.

Show comment
Hide comment
@trejkaz

trejkaz Jun 16, 2016

I had this same error message on multiple servers on the same day, and in all cases deleting the file made it work again the next time.

If this is a kind of pseudo-lock file, perhaps what rbenv could do is open and actually lock the file. Then a second rbenv which comes along and sees the file could simply try to delete it before recreating it.

trejkaz commented Jun 16, 2016

I had this same error message on multiple servers on the same day, and in all cases deleting the file made it work again the next time.

If this is a kind of pseudo-lock file, perhaps what rbenv could do is open and actually lock the file. Then a second rbenv which comes along and sees the file could simply try to delete it before recreating it.

@glebm

This comment has been minimized.

Show comment
Hide comment
@glebm

glebm Mar 2, 2017

This has failed for me just now on an Ubuntu 16.04 server:

Relevant Ansible output:

TASK [deploy-rails : Ensure ruby 2.4.0 is installed] *******************************************
fatal: [prod1]: FAILED! => {
  "cmd": "cd; bash -lc 'MAKEOPTS=\"-j $(getconf _NPROCESSORS_ONLN)\" CONFIGURE_OPTS=\"--disable-install-rdoc\" rbenv install 2.4.0'",
  "rc": 1,
  "stderr_lines": [
    "Downloading ruby-2.4.0.tar.bz2...",
    "-> https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.0.tar.bz2",
    "Installing ruby-2.4.0...",
    "Installed ruby-2.4.0 to /home/plforums/.rbenv/versions/2.4.0",
    "",
    "rbenv: cannot rehash: /home/plforums/.rbenv/shims/.rbenv-shim exists"
  ],
  "stdout_lines": []
}

No other commands were run in parallel. Both rbenv and ruby-build are from master as of 5 minutes ago.

After SSH'ing into the server and running rbenv uninstall 2.4.0, re-running the playbook has succeeded.

This does not seem like a user error. Seems to be a race condition in rbenv or ruby-build.

glebm commented Mar 2, 2017

This has failed for me just now on an Ubuntu 16.04 server:

Relevant Ansible output:

TASK [deploy-rails : Ensure ruby 2.4.0 is installed] *******************************************
fatal: [prod1]: FAILED! => {
  "cmd": "cd; bash -lc 'MAKEOPTS=\"-j $(getconf _NPROCESSORS_ONLN)\" CONFIGURE_OPTS=\"--disable-install-rdoc\" rbenv install 2.4.0'",
  "rc": 1,
  "stderr_lines": [
    "Downloading ruby-2.4.0.tar.bz2...",
    "-> https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.0.tar.bz2",
    "Installing ruby-2.4.0...",
    "Installed ruby-2.4.0 to /home/plforums/.rbenv/versions/2.4.0",
    "",
    "rbenv: cannot rehash: /home/plforums/.rbenv/shims/.rbenv-shim exists"
  ],
  "stdout_lines": []
}

No other commands were run in parallel. Both rbenv and ruby-build are from master as of 5 minutes ago.

After SSH'ing into the server and running rbenv uninstall 2.4.0, re-running the playbook has succeeded.

This does not seem like a user error. Seems to be a race condition in rbenv or ruby-build.

@MartinNowak

This comment has been minimized.

Show comment
Hide comment
@MartinNowak

MartinNowak Mar 26, 2017

Contributor

I'm getting a similar error, not b/c the lock file gets clobbered, but b/c of the 2>/dev/null redirect, which according to bash clobbers /dev/null.

Just test bash.

set -o noclobber
echo >/dev/null

bash --version

GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

That redirections needs to be done explicity, see Safe I/O Redirection with noclobber (Unix Power Tools, 3rd Edition).

Contributor

MartinNowak commented Mar 26, 2017

I'm getting a similar error, not b/c the lock file gets clobbered, but b/c of the 2>/dev/null redirect, which according to bash clobbers /dev/null.

Just test bash.

set -o noclobber
echo >/dev/null

bash --version

GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

That redirections needs to be done explicity, see Safe I/O Redirection with noclobber (Unix Power Tools, 3rd Edition).

@ykzts ykzts referenced this issue in tootsuite/mastodon Jul 18, 2017

Closed

Error: gemfile syntax error? #3884

@mislav mislav closed this in db39044 Nov 29, 2017

mislav added a commit that referenced this issue Nov 29, 2017

jrolfs added a commit to jrolfs/rbenv that referenced this issue Nov 30, 2017

partly resolve #759
- some versions of bash (e.g. 4.3.11) complain about clobbering
  /dev/null, use bash's explicit >| operator to ignore noclober
- not sure if the original #759 report has the same cause
- rbenv#759 (comment)
@jakesyl

This comment has been minimized.

Show comment
Hide comment
@jakesyl

jakesyl Jan 22, 2018

Any update on this? I still have this issue. I guess I'll check out #982 which reports to fix.

jakesyl commented Jan 22, 2018

Any update on this? I still have this issue. I guess I'll check out #982 which reports to fix.

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