Repository navigation
Fix Gem::URI redefinition warnings on older RubyGems - #10074
Merged
Merged
Conversation
The spec doesn't go through the artifice, which loads RubyGems' vendored net-http, and with it RubyGems' URI, before Bundler does. It only fails without the fix under RGV=system, which the system-rubygems-bundler job uses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 24, 2026
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?
Bundler 4.1.0, installed as a gem on the RubyGems that ships with Ruby 3.3, 3.4 or 4.0, prints 63 to 72
already initialized constant Gem::URI::…warnings on every command that talks to a remote.The bundler gem ships its own copy of
rubygems/vendor/uri, andvendored_uri.rbrequires it by feature name, which resolves to that copy. When Bundler then talks to a remote,Gem::Request.proxy_uriandGem::RemoteFetcher#initializeload RubyGems' own copy withrequire_relative, from a different path. Before RubyGems 4.1 that copy has no double load guard, so the library is loaded a second time.vendored_securerandom.rbhas the same latent problem.Fixes #10071.
What is your fix for the problem, implemented in this PR?
When the running RubyGems has its own copy of the vendored URI or SecureRandom, Bundler now requires that file by path through
Gem::RUBYGEMS_DIR, so Bundler and RubyGems load the same file once. Otherwise it requires the copy shipped in the bundler gem as before, with the stdlib as the last fallback. This is the same idea as #9684 forGem::TSort.Gem::YAMLSerializeris shipped the same way, but I left it out on purpose. With the same change, Bundler on RubyGems < 4.1 would read its config and plugin index with RubyGems' minimal serializer, which misreads files Bundler 4.1.0 has already written. That is tracked in #10073, which also proposes a fix for the YAML part.I checked it with bundler gems built from master and from this branch, on each Ruby's default RubyGems. Warnings printed by the reproduction from #10071 (
bundle outdatedthrough the binstub prints the same numbers):With this branch,
uri.rbis only loaded from RubyGems' own directory. The related specs (settings, fetcher, mirrors, remote sources, compact index and dependency API installs,bundle outdated,bundle config, plugins) pass withRGV=.andRGV=systemon Ruby 4.0.9.I didn't add a spec. The warnings only show up when Bundler runs as an installed gem on RubyGems < 4.1. The
system-rubygems-bundlerjob runs that setup and is green on master, although a real binstub prints the warnings on Ruby 3.3 and 3.4.Make sure the following tasks are checked