Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Fix Gem::URI redefinition warnings on older RubyGems - #10074

Merged
hsbt merged 2 commits into
ruby:masterfrom
top-sigrid:pw/load-uri-gem-once
Nov 17, 2026
Merged

hsbt merged 2 commits into
ruby:masterfrom
top-sigrid:pw/load-uri-gem-once

Conversation

@top-sigrid

Copy link
Copy Markdown
Contributor

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, and vendored_uri.rb requires it by feature name, which resolves to that copy. When Bundler then talks to a remote, Gem::Request.proxy_uri and Gem::RemoteFetcher#initialize load RubyGems' own copy with require_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.rb has 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 for Gem::TSort.

Gem::YAMLSerializer is 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 outdated through the binstub prints the same numbers):

Ruby RubyGems master this branch
3.3.6 3.5.22 72 0
3.4.8 3.6.9 63 0
4.0.9 4.0.20 65 0

With this branch, uri.rb is 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 with RGV=. and RGV=system on 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-bundler job 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

top-sigrid and others added 2 commits November 16, 2026 14:32
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bundler: bug fix skip old stable Leave out of releases on the old stable line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bundler 4.1.0 loads the vendored URI twice on RubyGems 3.5 to 4.0 ("already initialized constant Gem::URI::…")

2 participants