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

spring is not part of the bundle for production environment #447

Closed
dmilisic opened this issue Nov 18, 2015 · 13 comments · Fixed by #448
Closed

spring is not part of the bundle for production environment #447

dmilisic opened this issue Nov 18, 2015 · 13 comments · Fixed by #448

Comments

@dmilisic
Copy link

It seems that new binstub format (introduced with #444) is causing the issue in the production envrionment when the bundle is installed without development and test:

/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/rubygems_integration.rb:263:in `block in replace_gem': spring is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
    from /app/bin/spring:12:in `<top (required)>'
    from /app/bin/rake:4:in `load'
    from /app/bin/rake:4:in `<main>'

Full setup:
rails 2.4.5 application
ruby 2.2.3
spring 1.4.3
heroku cedar-14 stack
bundle is installed using bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment

The issue occurs when running heroku run rake db:migrate

@dmilisic
Copy link
Author

The simple workaround is to replace:

begin
  spring_bin_path = File.expand_path('../spring', __FILE__)
  load spring_bin_path
rescue LoadError => e
  raise unless e.message.end_with? spring_bin_path, 'spring/binstub'
end

with:

begin
  load File.expand_path('../spring', __FILE__)
rescue LoadError
end

in the bin/rake and bin/rails files

@grosser
Copy link
Collaborator

grosser commented Nov 18, 2015

yeah that's a bug ... it should ignore when the gem is not installed ...

@felixbuenemann to the rescue!

@felixbuenemann
Copy link
Contributor

I'll check it out.

@felixbuenemann
Copy link
Contributor

Yeah, this raises a Gem::LoadError which descends from LoadError. I had to gem uninstall spring to trigger it locally, even if I put spring in a different group. That's probably the reason it wasn't caught by the tests.

@felixbuenemann
Copy link
Contributor

@grosser There are two ways to handle this:

  1. The fix I originally suggested on warning: already initialized constant APP_PATH #259:
begin
  load File.expand_path('../spring', __FILE__)
rescue LoadError => e
  raise unless e.message =~ /spring/
end
  1. Handle Gem::LoadError explicitly, requires at least rubygems 2.0:
begin
  spring_bin_path = File.expand_path('../spring', __FILE__)
  load spring_bin_path
rescue Gem::LoadError => e
  raise unless e.name == 'spring'
rescue LoadError => e
  raise unless e.message.end_with? spring_bin_path, 'spring/binstub'
end

The first one is more likely to swallow unrelated errors the second one more likely to miss errors we don't yet know about.

Which direction do you want me to go? (I'm leaning towards one.)

@grosser
Copy link
Collaborator

grosser commented Nov 18, 2015

first one sounds simplest+safest to me ...

On Wed, Nov 18, 2015 at 8:58 AM, Felix Bünemann notifications@github.com
wrote:

@grosser https://github.com/grosser There are two ways to handle this:

  1. The fix I originally suggested on warning: already initialized constant APP_PATH #259
    warning: already initialized constant APP_PATH #259:

begin
load File.expand_path('../spring', FILE)rescue LoadError => e
raise unless e.message =~ /spring/end

  1. Handle Gem::LoadError explicitly, requires at least rubygems 2.0:

begin
spring_bin_path = File.expand_path('../spring', FILE)
load spring_bin_pathrescue Gem::LoadError => e
raise unless e.name == 'spring'rescue LoadError => e
raise unless e.message.end_with? spring_bin_path, 'spring/binstub'end

The first one is more likely to swallow unrelated errors the second one
more likely to miss errors we don't yet know about.

Which direction do you want me to go?


Reply to this email directly or view it on GitHub
#447 (comment).

@felixbuenemann
Copy link
Contributor

I've yet to be able to reproduce this in the acceptance tests, I'll try setting up a test app on heroku.

In the acceptance test I either get the LoadError for 'spring/binstub' (Gemfile.lock lists spring) or no error if I remove spring from the Gemfile.lock.

@dmilisic Do you check Gemfile.lock into git and could you post a gist of your Gemfile and Gemfile.lock?

@real-ashwin
Copy link

Fails on Heroku for me with the error below and I think it is the same issue. When I replaced the bin/rake and bin/rails from a 3 months old project, it fixed the issue.

Starting process with command `bin/rails server -p 43336 -e production`
2015-11-18T07:50:35.315901+00:00 app[web.1]: /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'spring' (= 1.4.3) among 62 total gem(s) (Gem::LoadError)
2015-11-18T07:50:35.315914+00:00 app[web.1]: Checked in 'GEM_PATH=/app/vendor/bundle/ruby/2.2.0:/app/vendor/ruby-2.2.2/lib/ruby/gems/2.2.0', execute `gem env` for more information
2015-11-18T07:50:35.315915+00:00 app[web.1]:    from /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rubygems/dependency.rb:324:in `to_spec'
2015-11-18T07:50:35.315916+00:00 app[web.1]:    from /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
2015-11-18T07:50:35.315917+00:00 app[web.1]:    from /app/bin/spring:12:in `<top (required)>'
2015-11-18T07:50:35.315917+00:00 app[web.1]:    from bin/rails:4:in `load'
2015-11-18T07:50:35.315920+00:00 app[web.1]:    from bin/rails:4:in `<main>'
2015-11-18T07:50:36.193020+00:00 heroku[web.1]: Process exited with status 1
2015-11-18T07:50:36.206171+00:00 heroku[web.1]: State changed from starting to crashed

@felixbuenemann
Copy link
Contributor

Thanks, I can reproduce it with the getting started example app on heroku.

@felixbuenemann
Copy link
Contributor

@grosser I think the reason I can't reproduce the Gem::LoadError in the acceptance tests is that rubygems loads the gemspec from the spring git repo, so gem 'spring', match[1] is successful, even if the gem is removed from the test app.

@grosser
Copy link
Collaborator

grosser commented Nov 18, 2015

PR without test then ?

On Wed, Nov 18, 2015 at 2:15 PM, Felix Bünemann notifications@github.com
wrote:

@grosser https://github.com/grosser I think the reason I can't
reproduce the Gem::LoadError in the acceptance tests is that rubygems
loads the gemspec from the spring git repo, so gem 'spring', match[1] is
successful, even if the gem is removed from the test app.


Reply to this email directly or view it on GitHub
#447 (comment).

@felixbuenemann
Copy link
Contributor

Yeah, I'll do that.

felixbuenemann added a commit to felixbuenemann/spring that referenced this issue Nov 18, 2015
felixbuenemann added a commit to felixbuenemann/spring that referenced this issue Nov 18, 2015
The previous binstub code did not catch Gem::LoadErrors which can
be generated by bundler or rubygems trying to load the spring gem.

This fixes rails#447.
@felixbuenemann
Copy link
Contributor

@dmilisic @ashwinputhige Should be fixed, please upgrade to spring 1.4.4 and don't forget to run bin/spring binstub --all to update the binstubs. Sorry for the trouble!

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 a pull request may close this issue.

4 participants