Perform the install triggered by auto_install in a subprocess - #9758
Open
meganemura wants to merge 1 commit into
Open
Perform the install triggered by auto_install in a subprocess#9758meganemura wants to merge 1 commit into
meganemura wants to merge 1 commit into
Conversation
With `auto_install`, Bundler installs missing gems in the same process that then runs `Bundler.setup`. Installing requires `openssl` for HTTPS remotes, and no Gemfile requirement is in effect yet, so RubyGems activates the default gem while the locked one is still missing. Activation can't be undone, so the `Bundler.setup` that follows raises a `Gem::LoadError` when the lockfile pins `openssl` to another version. Do the install in a forked child, like `bundler/inline` already does for the same reason. Platforms without `fork` keep installing in process. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
meganemura
force-pushed
the
auto-install-in-subprocess
branch
from
August 8, 2026 04:51
684bb30 to
d3d2b3d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was the end-user or developer problem that led to this PR?
With
auto_installenabled, the firstrequire "bundler/setup"(orbundle exec) after gems go missing installs them and then fails:The install itself succeeded, so running the same command again works, which makes it look unreproducible. Both suggestions in the error message are dead ends:
opensslis usually a transitive dependency that can't be dropped from the Gemfile, and the bundler in use is already current.Reproduction, on a Ruby whose default
openssldiffers from the pinned version:Only
auto_installis affected, since it is what chains an install and aBundler.setupin one process.bundle exec <binstub>reaches the same path;bundle exec ruby ...does not, becauserubyisKernel.execed and activation is reset.What is your fix for the problem, implemented in this PR?
Installing talks to the gem source over HTTPS, which requires
openssl.Bundler.setuphas not run at that point, so no Gemfile requirement is in effect and RubyGems activates the newest installed version, which is the default gem while the locked one is still missing. Activation is one version per process and can't be undone —reset!only drops Bundler'sDefinition, not RubyGems' activated specs — so theBundler.setupthat follows activates the lockfile's version and raises. Bundler normally avoids this class of conflict by vendoring what it needs, butopensslis a C extension and can't be vendored.So run the install in a forked child, the way
bundler/inlinealready does for the same reason, and keep installing in process on platforms withoutfork, also as inbundler/inline.Unlike
bundler/inline, this does not callGem.load_yamlbefore forking: on Ruby 3.2 that requirespsychunconditionally, activating the defaultpsychin the parent, which is the very conflict this PR removes.bundler/inlinecan afford the pre-activation because it recovers by re-resolving with the activated version; hereBundler.setupmust activate what the lockfile says. TheNameErrorthat call is meant to prevent did not occur, becauseBundler.setuphas already loaded the realPsychby the time YAML is loaded.Tests
spec/bundler/bundler_spec.rbcovers the install running in a subprocess and a failed install exiting with the child's status code.spec/runtime/setup_gems_spec.rbcovers an automatic install of a bundle that locks a default gem to another version; it uses apsych 999fixture rather thanopensslbecause the suite stubs HTTPS, the same stand-inspec/runtime/inline_spec.rbalready uses.Make sure the following tasks are checked