rbenv / rbenv-gem-rehash

DEPRECATED - Never run `rbenv rehash` again
MIT License
366 stars 10 forks source link

post_install hook fails #15

Open manuelmeurer opened 9 years ago

manuelmeurer commented 9 years ago

When I run bundle install with the sdoc gem in my Gemfile, I get this error:

...
post_install hook at
/home/chief/.rbenv/plugins/rbenv-gem-rehash/rubygems_plugin.rb:1 failed for
sdoc-0.4.1

I guess it's because the gem executes git when checking for executables: https://github.com/voloko/sdoc/blob/087940a7220b523a3a3758479552fcf81329b320/sdoc.gemspec#L37

Replacing this line with a simple array of the executables would probably fix this, but is there any other way to make this work properly?

manuelmeurer commented 9 years ago

The same thing just happened for passenger-enterprise-server (not a public gem)

post_install hook at /Users/manuel/.rbenv/plugins/rbenv-gem-rehash/rubygems_plugin.rb:1 failed for passenger-enterprise-server-3.0.17
skydan commented 9 years ago
post_install hook at /usr/local/Cellar/rbenv-gem-rehash/1.0.0/rubygems_plugin.rb:1 failed for jammit-0.6.6
mcmire commented 9 years ago

This has started to happen for me more often lately than before. I would imagine that rbenv rehash is actually failing in some way. I think it might be related to https://github.com/sstephenson/rbenv/issues/759. I have Bundler set to install gems in parallel, so after reading that issue I'm wondering if that's related somehow.

kinsomicrote commented 9 years ago

This happened to me minutes ago post_install hook at /home/kinsomicrote/.rbenv/plugins/rbenv-gem-rehash/rubygems_plugin.rb:1 failed for spree_cmd-3.0.5.beta Any solution?

LunarDevelopment commented 8 years ago

I've also getting this issue but the chances of it getting solved after being open for over a year are slim I'm guessing..

igorshtopor commented 8 years ago

Had same for private repo. Will update if find out any details

NicoBuch commented 8 years ago

Try deleting rbenv-shim:

rm ~/.rbenv/shims/.rbenv-shim
marcinhlybin commented 2 years ago

If you ever stumble across this error here is a quick explanation what is happening and how to fix it.

After installing executables rbenv is rehashing shims by running rbenv rehash (~/.rbenv/libexec/rbenv-rehash). By default bundle install is using --jobs option set to the number of available processors.

Because bundle is installing gems in parallel, rbenv rehash may run in the same time for two gems leading to a race condition. Normally it wouldn't be a problem because rbenv will never run twice due to the lock file it creates in ~/.rbenv/shims/.rbenv-shim. Unfortunately the code for doing so looks like this:

set -o noclobber
{ echo > "$PROTOTYPE_SHIM_PATH"
} 2>| /dev/null ||
{ if [ -w "$SHIM_PATH" ]; then
    echo "rbenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists"
  else
    echo "rbenv: cannot rehash: $SHIM_PATH isn't writable"
  fi
  exit 1
} >&2
set +o noclobber

The noclobber option means that bash will not let you redirect to the existing file with >. If the file exists it will go straight to the if conditional to decide which message to display AND THEN it will exit with exit code 1.

Post install hook will interpret it as an error while installing a gem.

THE SOLUTION

You either:

  1. run bundle with -j1 which is slower but will not lead to a race condition because it will only use one thread.
  2. in the code listed above in ~/.rbenv/shims/.rbenv-shim change exit 1 to exit 0. Not ideal but it works. For CI you can do it easily with sed by running:
sed -i.bak 's/exit 1/exit 0/g' ~/.rbenv/libexec/rbenv-rehash