Autoload RubyGems internals by feature name - #9830
Open
hsbt wants to merge 2 commits into
Open
Conversation
An absolute path skips the `$LOADED_FEATURES` check, so a second RubyGems tree on the load path gets loaded on top of the one already loading and redefines every method in it. A checkout hits this through `exe/bundle`, which puts its `lib` first and now ships RubyGems next to Bundler there. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This is the last autoload left holding an absolute path. Nothing loads a second copy of it today, but it carries the same hazard as the ones in `rubygems.rb`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Gemautoloads its own constants by absolute path, and an absolute path skips the$LOADED_FEATUREScheck. When a second RubyGems tree sits on the load path, the copy that is still loading pulls the other one in through that autoload, and every method it defines gets redefined on top of it.Running
exe/bundlefrom a checkout triggers this now thatlibholds RubyGems and Bundler side by side. UnderRUBYOPT=-wa singlebundle --versionprints 175 redefinition warnings, 14 of them fromname_tuple.rb. Autoloading by feature name takes the same lookup an ordinaryrequiredoes, so only one copy is loaded.The test starts a child with a second copy of
rubygems/name_tuple.rbahead of the real one and asserts that$LOADED_FEATURESholds exactly one.