Skip to content

Conversation

@k0kubun
Copy link
Contributor

@k0kubun k0kubun commented Jul 9, 2019

Since Ruby 2.6.0, bundler.gem has been a default gem. It means that $LOADED_FEATURES.grep(/bundler\/setup\.rb$/).first could be the same as RbConfig::CONFIG["rubylibdir"], which is the default gem directory and not dedicated for a specific bundler version, if no newer bundler were manually installed.

Passing default gem directory with -I is really problematic because it has other default gems like json.gem, and -I is prioritized more than $LOAD_PATHs added by Bundler.require. Using default-gem Bundler could cause a wrong default gem version on spring server process.

@k0kubun
Copy link
Contributor Author

k0kubun commented Jul 9, 2019

Reproductive steps

# Use clean Ruby 2.6.x, or uninstall any non-default bundler installation
$ rails new springapp --skip-active-record
$ cd springapp
$ echo 'gem "json", "1.8.6"' >> Gemfile
$ bundle install

$ DISABLE_SPRING=1 bin/rails r 'p JSON.load(nil)'
nil

$ DISABLE_SPRING=0 bin/rails r 'p JSON.load(nil)'
Running via Spring preloader in process 17934
Traceback (most recent call last):
# ...
/home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/json/common.rb:156:in `parse': 784: unexpected token at 'null' (JSON::ParserError)

I believe this is not something we want.

Example

$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]

$ rails -v
Rails 5.2.3

$ gem list | grep bundler
bundler (default: 1.17.2)

$ rails new springapp --skip-active-record
# ...

$ cd springapp
$ echo 'gem "json", "1.8.6"' >> Gemfile
$ bundle install
# ...

$ bundle exec spring -v
Spring version 2.1.0

$ DISABLE_SPRING=1 bin/rails r 'p JSON.load(nil)'
nil

$ bin/spring stop
Spring is not running

$ DISABLE_SPRING=0 bin/rails r 'p JSON.load(nil)'
Running via Spring preloader in process 17934
Traceback (most recent call last):
        28: from -e:1:in `<main>'
        27: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        26: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        25: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:285:in `load'
        24: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
        23: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:285:in `block in load'
        22: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
        21: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
        20: from /home/k0kubun/tmp/springapp/bin/rails:9:in `<main>'
        19: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
        18: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
        17: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
        16: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        15: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
        14: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        13: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
        12: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
        11: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<main>'
        10: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/command.rb:46:in `invoke'
         9: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/command/base.rb:65:in `perform'
         8: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
         7: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
         6: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
         5: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/commands/runner/runner_command.rb:41:in `perform'
         4: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/commands/runner/runner_command.rb:41:in `eval'
         3: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/commands/runner/runner_command.rb:41:in `<main>'
         2: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/json/common.rb:335:in `load'
         1: from /home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/json/common.rb:156:in `parse'
/home/k0kubun/.rbenv/versions/2.6.3/lib/ruby/2.6.0/json/common.rb:156:in `parse': 784: unexpected token at 'null' (JSON::ParserError)

Copy link
Member

@kamipo kamipo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 People who using Ruby 2.6 may be faced with this issue as we've faced.

@kamipo kamipo merged commit caa09ef into rails:master Jul 10, 2019
@k0kubun k0kubun deleted the default-gem-bundler branch July 11, 2019 00:21
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.

2 participants