⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@Edouard-chin
Copy link
Contributor

Fix Bundler that re-exec $0 when a version is present in the config:

Problem

If you have a version in your config file (this feature was introduced in #6817), then running any bundle command will make Bundler re-exec and ultimately run the bundle binstub twice.

Details

When the bundle binstub gets executed, a require "bundler" is evaluated. RubyGems tries to require the bundler.rb file from the right bundler gem (in the event where you have multiple bundler versions in your system). RubyGems will prioritize a bundler version based on a few heurisitics.

def self.prioritize!(specs)
exact_match_index = specs.find_index {|spec| spec.version == bundler_version }
return unless exact_match_index

This prioritize logic doesn't take into account the bundler version a user has specified in its config. So what happens is:

  1. User execute the bundle binstub
  2. require 'bundler' is evaluated.
  3. RubyGems prioritize activating the bundler version specified in the Gemfile.lock
  4. The CLI starts, and Auto switch kicks in. Bundler detects that user has a specific version in its config and the current runtime Bundler version doesn't match.
  5. Bundler exit and re-exec with the right bundler version.

Solution

This patch introduce two fixes. First, it reads the bundler config file and check for the local config and then the global config. This is because the local has precedence over global (see the order here.

Second, the prioritization takes into account the version in a user's config and let RubyGems activate the right version in order to prevent re-exec moments later.

Finally, I also want to fix this problem because its a step toward fixing #8106. I'll open a follow up patch to explain.

Make sure the following tasks are checked

- ### Problem

  If you have a `version` in your config file (this feature was
  introduced in ruby#6817), then running any `bundle` command will
  make Bundler re-exec and ultimately run the `bundle` binstub twice.

  ### Details

  When the `bundle` binstub gets executed, a `require "bundler"` is
  evaluated. RubyGems tries to require the `bundler.rb` file from
  the right `bundler` gem (in the event where you have multiple
  bundler versions in your system).
  RubyGems will prioritize a bundler version based on a few
  heurisitics.

  https://github.com/ruby/rubygems/blob/b50c40c92abb00bb172f1579356cc73c242b1849/lib/rubygems/bundler_version_finder.rb#L19-L21

  This prioritize logic doesn't take into account the bundler version
  a user has specific in this config. So what happens is:

  1. User execute the `bundle` binstub
  2. `require 'bundler'` is evaluated.
  3. RubyGems prioritize activating the bundler version specified
     in the Gemfile.lock
  4. The CLI starts, and [Auto switch kicks in](https://github.com/ruby/rubygems/blob/b50c40c92abb00bb172f1579356cc73c242b1849/bundler/lib/bundler/cli.rb#L81). Bundler detects that
     user specifed a version in its config and the current Bundler
     version doesn't match.
  5. Bundler exit and re-exec with the right bundler version.

  ### Solution

  This patch introduce two fixes. First, it reads the bundler config
  file and check for the local config first and then the global
  config. This is because the local has precedence over global.

  Second, the prioritization takes into account the version in config
  and let RubyGems activate the right version in order to prevent
  re-exec moments later.

  Finally, I also want to fix this problem because its a step toward
  fixing ruby#8106. I'll open
  a follow up patch to explain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants