Skip to content

Spring is not bypassed in production #646

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

Closed
dzhlobo opened this issue May 16, 2021 · 3 comments
Closed

Spring is not bypassed in production #646

dzhlobo opened this issue May 16, 2021 · 3 comments

Comments

@dzhlobo
Copy link

dzhlobo commented May 16, 2021

I have spring in development group in my Gemfile. I install dependencies for production using bundle install --without development test. When I run bin/rails in production (and it seems that even if I run bundle exec rails bin/rails with spring is still invoked) it fails:

/usr/local/lib/ruby/3.0.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'spring' (= 2.1.1) among 141 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=/api/vendor/bundle/ruby/3.0.0:/home/api/.local/share/gem/ruby/3.0.0:/usr/local/lib/ruby/gems/3.0.0:/usr/local/bundle' , execute `gem env` for more information
        from /usr/local/lib/ruby/3.0.0/rubygems/dependency.rb:323:in `to_spec'
        from /usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_gem.rb:62:in `gem'
        from /api/bin/spring:14:in `<top (required)>'
        from bin/rails:7:in `load'
        from bin/rails:7:in `<main>'

I expected spring is bypassed. But it seems it is not.

I don't understand how bypassing technically should occure. Here's the bin/spring:

#!/usr/bin/env ruby

# This file loads Spring without using Bundler, in order to be fast.
# It gets overwritten when you run the `spring binstub` command.

unless defined?(Spring)
  require 'rubygems'
  require 'bundler'

  lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
  spring = lockfile.specs.detect { |spec| spec.name == 'spring' }
  if spring
    Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
    gem 'spring', spring.version
    require 'spring/binstub'
  end
end

/api/bin/spring:14:

gem 'spring', spring.version

From what I understand, spring is always present in lockfile therefore bin/spring finds it and tries to load but fails since it is not installed because I excluded the "development" group during bundle install.

Maybe rubygem's behavior was changed in recent versions so gem 'spring', spring.version fails now and we need to amend binstub's code accordingly?

Without knowing too much about rubygems I would fix it with catching the Gem::MissingSpecError exception and just ignoring it. What do you think?

@dzhlobo
Copy link
Author

dzhlobo commented May 16, 2021

I'd be happy to send a pull request but I might use some help in writing test for this.

@deivid-rodriguez
Copy link
Contributor

The template generated by Rails these days swallows the error since rails/rails@2a4fa7e, so you probably want to do the same thing.

@rafaelfranca
Copy link
Member

Yes. Please update your binstubs

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

No branches or pull requests

3 participants