Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundler 2.3.7 causing uninitialized constant Gem::Source and CRITICAL: RUBYGEMS_ACTIVATION_MONITOR.owned?: before false -> after true errors #5351

Closed
timsutton opened this issue Feb 11, 2022 · 26 comments · Fixed by #5386
Labels

Comments

@timsutton
Copy link
Contributor

Describe the problem as clearly as you can

I've observed that when we have gem installed the latest bundler 2.3.7 version, that it causes a rubygems crash when I attempt to invoke a bin exe of a small internal gem. We aren't using bundler to invoke the gem, however I guessed that this is at least in some way related to Bundler as I can't reproduce it when 2.3.6 is installed.

Did you try upgrading rubygems & bundler?

I did not. The reason is that I can only reproduce this on our Mac CI machines, which use RVM to provide Ruby 2.7.x. RubyGems on this version is currently at 3.1.6.

I can still try this to see if the problem goes away, but I wanted to get this issue logged first since the CRITICAL: RUBYGEMS_ACTIVATION_MONITOR.owned?: before false -> after true (RuntimeError) error struck me as something definitely unexpected.

Post steps to reproduce the problem

I can work on more specific repro cases for this but I don't have anything immediately to share - I might need to find some small "exemplar" gem as an internal example. This gem has one dependency but that gem is also internal. I have not yet tried to find other public gems that might exhibit this same issue.

The system is:

  • macOS 11.5.2
  • Ruby 2.7.4 is provided via RVM, we aren't explicitly upgrading rubygems, and are installing bundler via gem install bundler

Bundler 2.1.4 happens to be the 'default' version, but bundle commands do use the latest version installed, and I do see bundler-2.3.7 library paths as part of the traceback in the error I've included below.

Which command did you run?

Here's a sample of how I'd invoke our internal gem:

$ rvm 2.7.4 do my-internal-gem --help

I have tried the same thing with explicitly setting 2.7.4 to be the RVM default via rvm use 2.7.4 --default and then omitting the rvm 2.7.4 do commands, just to eliminate this as a variable.

It's installed here:

$ which my-internal-gem
/Users/build/.rvm/gems/ruby-2.7.4/bin/my-internal-gem

The bin exe was installed originally via:

rvm 2.7.4 do gem install --clear-sources --no-document --source 'https://my.gemstash.mirror' --source 'https://my.gemstash.mirror/private' my-internal-gem:0.7.0```

What were you expecting to happen?

I would normally just get our gem exe's help output, i.e.

Usage: my-internal-gem --option=[possible,values]
        --option=
[etc]

What actually happened?

[66796, #<Thread:0x00007fd51505fa90 run>, #<NameError: uninitialized constant Gem::Source>, ["/Users/build/.rvm/gems/ruby-2.7.4/gems/bundler-2.3.7/lib/bundler/rubygems_ext.rb:18:in `source'", "/Users/build/.rvm/gems/ruby-2.7.4/gems/bundler-2.3.7/lib/bundler/rubygems_ext.rb:50:in `extension_dir'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/basic_specification.rb:53:in `gem_build_complete_path'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2133:in `missing_extensions?'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/basic_specification.rb:78:in `contains_requirable_file?'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:1043:in `block (2 levels) in find_in_unresolved_tree'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2566:in `block (2 levels) in traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `each'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `block in traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `each'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2572:in `block (2 levels) in traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `each'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `block in traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `each'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2572:in `block (2 levels) in traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `each'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `block in traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `each'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2572:in `block (2 levels) in traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `each'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `block in traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `each'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2572:in `block (2 levels) in traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `each'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `block in traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `each'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `traverse'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:1039:in `block in find_in_unresolved_tree'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:1038:in `each'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:1038:in `find_in_unresolved_tree'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:112:in `require'", "/Users/build/.rvm/gems/ruby-2.7.4/gems/bundler-2.3.7/lib/bundler/rubygems_ext.rb:18:in `source'", "/Users/build/.rvm/gems/ruby-2.7.4/gems/bundler-2.3.7/lib/bundler/rubygems_ext.rb:29:in `full_gem_path'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/basic_specification.rb:152:in `block in full_require_paths'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/basic_specification.rb:151:in `map'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/basic_specification.rb:151:in `full_require_paths'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:1503:in `add_self_to_load_path'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:1372:in `activate'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems.rb:298:in `block in activate_bin_path'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems.rb:297:in `synchronize'", "/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems.rb:297:in `activate_bin_path'", "/Users/build/.rvm/gems/ruby-2.7.4/bin/my-internal-gem:23:in `<main>'", "/Users/build/.rvm/gems/ruby-2.7.4/bin/ruby_executable_hooks:22:in `eval'", "/Users/build/.rvm/gems/ruby-2.7.4/bin/ruby_executable_hooks:22:in `<main>'"]]
Traceback (most recent call last):
	47: from /Users/build/.rvm/gems/ruby-2.7.4/bin/ruby_executable_hooks:22:in `<main>'
	46: from /Users/build/.rvm/gems/ruby-2.7.4/bin/ruby_executable_hooks:22:in `eval'
	45: from /Users/build/.rvm/gems/ruby-2.7.4/bin/my-internal-gem:23:in `<main>'
	44: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems.rb:297:in `activate_bin_path'
	43: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems.rb:297:in `synchronize'
	42: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems.rb:298:in `block in activate_bin_path'
	41: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:1372:in `activate'
	40: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:1503:in `add_self_to_load_path'
	39: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/basic_specification.rb:151:in `full_require_paths'
	38: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/basic_specification.rb:151:in `map'
	37: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/basic_specification.rb:152:in `block in full_require_paths'
	36: from /Users/build/.rvm/gems/ruby-2.7.4/gems/bundler-2.3.7/lib/bundler/rubygems_ext.rb:29:in `full_gem_path'
	35: from /Users/build/.rvm/gems/ruby-2.7.4/gems/bundler-2.3.7/lib/bundler/rubygems_ext.rb:18:in `source'
	34: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:112:in `require'
	33: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:1038:in `find_in_unresolved_tree'
	32: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:1038:in `each'
	31: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:1039:in `block in find_in_unresolved_tree'
	30: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `traverse'
	29: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `each'
	28: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `block in traverse'
	27: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `each'
	26: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2572:in `block (2 levels) in traverse'
	25: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `traverse'
	24: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `each'
	23: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `block in traverse'
	22: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `each'
	21: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2572:in `block (2 levels) in traverse'
	20: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `traverse'
	19: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `each'
	18: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `block in traverse'
	17: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `each'
	16: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2572:in `block (2 levels) in traverse'
	15: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `traverse'
	14: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `each'
	13: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `block in traverse'
	12: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `each'
	11: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2572:in `block (2 levels) in traverse'
	10: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `traverse'
	 9: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2559:in `each'
	 8: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `block in traverse'
	 7: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2561:in `each'
	 6: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2566:in `block (2 levels) in traverse'
	 5: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:1043:in `block (2 levels) in find_in_unresolved_tree'
	 4: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/basic_specification.rb:78:in `contains_requirable_file?'
	 3: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:2133:in `missing_extensions?'
	 2: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/basic_specification.rb:53:in `gem_build_complete_path'
	 1: from /Users/build/.rvm/gems/ruby-2.7.4/gems/bundler-2.3.7/lib/bundler/rubygems_ext.rb:50:in `extension_dir'
/Users/build/.rvm/gems/ruby-2.7.4/gems/bundler-2.3.7/lib/bundler/rubygems_ext.rb:18:in `source': uninitialized constant Gem::Source (NameError)
	14: from /Users/build/.rvm/gems/ruby-2.7.4/bin/ruby_executable_hooks:22:in `<main>'
	13: from /Users/build/.rvm/gems/ruby-2.7.4/bin/ruby_executable_hooks:22:in `eval'
	12: from /Users/build/.rvm/gems/ruby-2.7.4/bin/my-internal-gem:23:in `<main>'
	11: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems.rb:297:in `activate_bin_path'
	10: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems.rb:297:in `synchronize'
	 9: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems.rb:298:in `block in activate_bin_path'
	 8: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:1372:in `activate'
	 7: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/specification.rb:1503:in `add_self_to_load_path'
	 6: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/basic_specification.rb:151:in `full_require_paths'
	 5: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/basic_specification.rb:151:in `map'
	 4: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/basic_specification.rb:152:in `block in full_require_paths'
	 3: from /Users/build/.rvm/gems/ruby-2.7.4/gems/bundler-2.3.7/lib/bundler/rubygems_ext.rb:29:in `full_gem_path'
	 2: from /Users/build/.rvm/gems/ruby-2.7.4/gems/bundler-2.3.7/lib/bundler/rubygems_ext.rb:18:in `source'
	 1: from /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:165:in `require'
/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:165:in `ensure in require': CRITICAL: RUBYGEMS_ACTIVATION_MONITOR.owned?: before false -> after true (RuntimeError)

These are other bundler versions I had installed:

$ rvm 2.7.4 do gem list bundler

*** LOCAL GEMS ***

bundler (2.3.7, 2.3.6, 2.2.33, 2.2.32, 2.2.30, 2.2.29, default: 2.1.4)
bundler-unload (1.0.2)
rubygems-bundler (1.4.5)

What is interesting is that if I remove 2.3.7 like this:

$ gem uninstall bundler -v2.3.7
Successfully uninstalled bundler-2.3.7

... the command works fine. I can then put it back via gem install bundler -v.2.3.7, and will get the same error/traceback again.

If not included with the output of your command, run bundle env and paste the output below

Environment

Bundler             2.3.7
  Platforms         ruby, x86_64-darwin-20
Ruby                2.7.4p191 (2021-07-07 revision a21a3b7d23704a01d34bd79d09dc37897e00922a) [x86_64-darwin-20]
  Full Path         /Users/build/.rvm/rubies/ruby-2.7.4/bin/ruby
  Config Dir        /Users/build/.rvm/rubies/ruby-2.7.4/etc
RubyGems            3.1.6
  Gem Home          /Users/build/.rvm/gems/ruby-2.7.4
  Gem Path          /Users/build/.rvm/gems/ruby-2.7.4:/Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/gems/2.7.0
  User Home         /Users/build
  User Path         /Users/build/.gem/ruby/2.7.0
  Bin Dir           /Users/build/.rvm/gems/ruby-2.7.4/bin
Tools               
  Git               2.33.1
  RVM               1.29.12 (1.29.12)
  rbenv             not installed
  chruby            not installed
  rubygems-bundler  (1.4.5)

Bundler Build Metadata

Built At          2022-02-09
Git SHA           bafe43c593
Released Version  true
@deivid-rodriguez
Copy link
Member

Definitely broken by 31bba75. Not fully sure why though, a reproducible case would be very helpful, I guess it's related to some gems RVM installs by default and that hook too much into bundler internals. I think you can workaround this by removing the executable-hooks gem.

@deivid-rodriguez
Copy link
Member

Also you can try upgrading RubyGems through gem update --system.

@timsutton
Copy link
Contributor Author

@deivid-rodriguez Thank you for identifying that so quickly. I have long-wondered whether executable-hooks is something we even rely on at all, we recently stopped installing it on our new machines, but I suspect either RVM or perhaps some other gems we have maybe implicitly pull in rubygems-bundler which pulls that in.

Does rubygems-bundler strike you as being a somewhat risky dependency? I see it's not updated in a few years, and I'm generally concerned with how much indirection is going on at that point 😅

I did try gem update --system to bring it to 3.3.7, but get the same crash.

@deivid-rodriguez
Copy link
Member

deivid-rodriguez commented Feb 11, 2022

rubygems-bundler is some initial work from the RVM team on removing the need to prefix commands with bundle exec (for example, bundle exec <my-gem-executable>), but still getting the version of gems in your Gemfile.lock file used automatically (in the example, of <my-gem-executable>).

We have been working on providing this functionality inside RubyGems/Bundler, specifically by setting the RUBYGEMS_GEMDEPS=- environment variable. However there are still some issues with it (in particular, #4862), which we need to figure out before it can be enabled by default.

In any case, if you prefix your commands with bundle exec, or don't care about this at all, you definitely don't need rubygems-bundler. It is indeed a problematic gem, and I'll request RVM no longer installs it by default once we figure out an alternative.

@timsutton
Copy link
Contributor Author

Thanks for that context, I've been wondering for a while what was the original use-case for some of those gems especially as they seemed dated (while at the same time being part of RVM's install).

To answer your earlier point, indeed once I uninstall rubygems-bundler and executable-hooks:

$ gem uninstall --executables -i /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/gems/2.7.0 executable-hooks
Removing executable-hooks-uninstaller
Successfully uninstalled executable-hooks-1.6.1

$ gem uninstall -i /Users/build/.rvm/rubies/ruby-2.7.4/lib/ruby/gems/2.7.0 rubygems-bundler
Successfully uninstalled rubygems-bundler-1.4.5

things work again. I'll plan to look to see if we can remove those gems as part of our RVM installation and that we're not relying on that particular behaviour unintentionally.

@deivid-rodriguez
Copy link
Member

deivid-rodriguez commented Feb 11, 2022

If you happen to be able to provide a small example to reproduce this, I'd be happy to have a closer look. Unfortunately all RVM users get these gems by default, so we should probably revert the change but it'd be nice to cover the revert with some test to ensure that I don't cause the same trouble again in the future.

@eamonn-webster
Copy link

lib/bundler/rubygems_ext.rb explicitly references Gem::Source::Installed on line 19 but does not require it.
adding require "rubygems/source" "fixes" the problem.
I don't have a reproduceable case case.

@deivid-rodriguez
Copy link
Member

Yes, we already identified the change that removed the require and caused this issue. But I don't fully understand why it happened because RubyGems should be autoloading Gem::Source. I'm now guessing that this usage is happening while loading a RubyGems plugin provided by RVM, and at that point the autoload is not already setup.

I will have a closer look to find a reproducible case, and regardless of that I will revert the change.

@javierav
Copy link

I have the same problem after upgrade rubygems to latest using gem update --system.

  • Ruby 3.0.2p107 on Apple M1.
  • Bundler upgraded from 2.2.29 to 2.3.7
  • Using asdf-ruby as version manager.

@deivid-rodriguez
Copy link
Member

deivid-rodriguez commented Feb 23, 2022

Sorry I forgot about this, I will ship this revert with the next version (2.3.9)

schneems added a commit to heroku/heroku-buildpack-ruby that referenced this issue Mar 2, 2022
Bundler 2.3.7 caused issues:

- rubygems/rubygems#5351
- #1280 


Internal (private) tickets:

- https://heroku.support/1083230
- https://heroku.support/1081495
- https://heroku.support/1082829


I've already rolled back the build pack deploy via the buildpack CLI. This commit is intended to represent the currently deployed software accurately in the codebase.
schneems added a commit to heroku/heroku-buildpack-ruby that referenced this issue Mar 3, 2022
Bundler 2.3.7 caused issues:

- rubygems/rubygems#5351
- #1280 


Internal (private) tickets:

- https://heroku.support/1083230
- https://heroku.support/1081495
- https://heroku.support/1082829


I've already rolled back the build pack deploy via the buildpack CLI. This commit is intended to represent the currently deployed software accurately in the codebase.
@shawnacscott
Copy link

shawnacscott commented Mar 4, 2022

It appears this issue has a resolution already, but I didn't see the requested small reproduction case, so I thought I'd offer mine in case it is helpful. I am able to reproduce this issue with this script. Downgrading to Bundler v2.3.6 resolves the issue.

#!/usr/bin/env ruby

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'nap', require: 'rest'
end

Notably, I do not use RVM. Instead, I rely on Rbenv.

Here is my bundle env:

Environment

Bundler       2.3.8
  Platforms   ruby, x86_64-darwin-19
Ruby          3.0.3p157 (2021-11-24 revision 3fb7d2cadc18472ec107b14234933b017a33c14d) [x86_64-darwin-19]
  Full Path   /Users/shawnascott/.rbenv/versions/3.0.3/bin/ruby
  Config Dir  /Users/shawnascott/.rbenv/versions/3.0.3/etc
RubyGems      3.2.32
  Gem Home    /Users/shawnascott/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0
  Gem Path    /Users/shawnascott/.gem/ruby/3.0.0:/Users/shawnascott/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0
  User Home   /Users/shawnascott
  User Path   /Users/shawnascott/.gem/ruby/3.0.0
  Bin Dir     /Users/shawnascott/.rbenv/versions/3.0.3/bin
Tools         
  Git         2.34.1
  RVM         not installed
  rbenv       rbenv 1.2.0
  chruby      not installed

Bundler Build Metadata

Built At          2022-02-23
Git SHA           4e812b9ca5
Released Version  true

Bundler settings

build.thin
  Set for the current user (/Users/shawnascott/.bundle/config): "--with-cflags=-Wno-error=implicit-function-declaration"
[REDACTED -- private gem source]
  Set for the current user (/Users/shawnascott/.bundle/config): "shawna.scott%40[REDACTED]:[REDACTED]"

@deivid-rodriguez
Copy link
Member

Thank you, no not yet, we know the culprit and I will revert the offending commit for 2.3.9, but having a reproducible case is very useful so that we can cover the fix with a regression spec. Thanks so much!

@deivid-rodriguez
Copy link
Member

deivid-rodriguez commented Mar 5, 2022

@shawnacscott I can not reproduce the issue using the same Ruby, RubyGems, Bundler and Rbenv version that you are using. Can you share the list of gems you have installed locally? (gem list)

@deivid-rodriguez
Copy link
Member

Alright, I managed to reproduce this locally using

$ ruby -rbundler -S irb                
[7668, #<Thread:0x0000000100c3cd18 run>, #<NameError: uninitialized constant Gem::Source

      (defined?(@source) && @source) || Gem::Source::Installed.new
                                           ^^^^^^^^
Did you mean?  Gem::SourceList>, ["/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/bundler-2.3.8/lib/bundler/rubygems_ext.rb:18:in `source'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/bundler-2.3.8/lib/bundler/rubygems_ext.rb:50:in `extension_dir'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/basic_specification.rb:339:in `have_file?'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/basic_specification.rb:86:in `contains_requirable_file?'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1038:in `block (2 levels) in find_in_unresolved_tree'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2555:in `block (2 levels) in traverse'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2550:in `each'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2550:in `block in traverse'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2548:in `each'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2548:in `traverse'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1034:in `block in find_in_unresolved_tree'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1033:in `each'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1033:in `find_in_unresolved_tree'", "<internal:/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:114:in `require'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/bundler-2.3.8/lib/bundler/rubygems_ext.rb:18:in `source'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/bundler-2.3.8/lib/bundler/rubygems_ext.rb:50:in `extension_dir'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/basic_specification.rb:339:in `have_file?'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/basic_specification.rb:86:in `contains_requirable_file?'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1038:in `block (2 levels) in find_in_unresolved_tree'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2555:in `block (2 levels) in traverse'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2550:in `each'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2550:in `block in traverse'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2548:in `each'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2548:in `traverse'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1034:in `block in find_in_unresolved_tree'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1033:in `each'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1033:in `find_in_unresolved_tree'", "<internal:/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:114:in `require'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems.rb:226:in `finish_resolve'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems.rb:287:in `block in activate_bin_path'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems.rb:285:in `synchronize'", "/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems.rb:285:in `activate_bin_path'", "/Users/deivid/.rbenv/versions/3.1.1/bin/irb:25:in `<main>'"]]
<internal:/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:167:in `ensure in require': CRITICAL: RUBYGEMS_ACTIVATION_MONITOR.owned?: before false -> after true (RuntimeError)
	from <internal:/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:167:in `require'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems.rb:226:in `finish_resolve'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems.rb:287:in `block in activate_bin_path'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems.rb:285:in `synchronize'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems.rb:285:in `activate_bin_path'
	from /Users/deivid/.rbenv/versions/3.1.1/bin/irb:25:in `<main>'
/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/bundler-2.3.8/lib/bundler/rubygems_ext.rb:18:in `source': uninitialized constant Gem::Source (NameError)

      (defined?(@source) && @source) || Gem::Source::Installed.new
                                           ^^^^^^^^
Did you mean?  Gem::SourceList
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/bundler-2.3.8/lib/bundler/rubygems_ext.rb:50:in `extension_dir'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/basic_specification.rb:339:in `have_file?'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/basic_specification.rb:86:in `contains_requirable_file?'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1038:in `block (2 levels) in find_in_unresolved_tree'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2555:in `block (2 levels) in traverse'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2550:in `each'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2550:in `block in traverse'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2548:in `each'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2548:in `traverse'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1034:in `block in find_in_unresolved_tree'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1033:in `each'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1033:in `find_in_unresolved_tree'
	from <internal:/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:114:in `require'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/bundler-2.3.8/lib/bundler/rubygems_ext.rb:18:in `source'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/bundler-2.3.8/lib/bundler/rubygems_ext.rb:50:in `extension_dir'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/basic_specification.rb:339:in `have_file?'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/basic_specification.rb:86:in `contains_requirable_file?'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1038:in `block (2 levels) in find_in_unresolved_tree'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2555:in `block (2 levels) in traverse'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2550:in `each'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2550:in `block in traverse'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2548:in `each'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:2548:in `traverse'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1034:in `block in find_in_unresolved_tree'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1033:in `each'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/specification.rb:1033:in `find_in_unresolved_tree'
	from <internal:/Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:114:in `require'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems.rb:226:in `finish_resolve'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems.rb:287:in `block in activate_bin_path'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems.rb:285:in `synchronize'
	from /Users/deivid/.rbenv/versions/3.1.1/lib/ruby/site_ruby/3.1.0/rubygems.rb:285:in `activate_bin_path'
	from /Users/deivid/.rbenv/versions/3.1.1/bin/irb:25:in `<main>'

I'll try to reproduce this error in CI, so that it fails without the revert.

@deivid-rodriguez
Copy link
Member

Alright I managed to reproduce this error in CI: https://github.com/rubygems/rubygems/runs/5455765474?check_suite_focus=true. Tomorrow I will get the fix ready!

@tanelsuurhans
Copy link

Getting this error on bundler 2.3.8 and rubygems 3.3.8 - no RVM etc, Ruby 2.5.8 compiled straight from source. Happens in from /usr/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:167:in require'`

@timsutton
Copy link
Contributor Author

Thank you so much for addressing this issue, even though the underlying issue is caused by an older gem and not part of Rubygems's own distribution!

@deivid-rodriguez
Copy link
Member

No problem @timsutton! In the end the issue turned out to be more widespread and reproducible without this RVM old gem. That made it more clear that we needed to address this :)

@briancolfer
Copy link

For me renaming the Gemfile.lock to Gemfile.lock.copy, running bundle install and then removing the Gemfile.lock.copy
resolved the problem for me.

@3htomit
Copy link

3htomit commented Jun 1, 2022

For me renaming the Gemfile.lock to Gemfile.lock.copy, running bundle install and then removing the Gemfile.lock.copy resolved the problem for me.

@briancolfer , thanks for the tips! It worked perfectly for me.

@deivid-rodriguez
Copy link
Member

I guess people are having issues to upgrade bundler when they run into this issue. Does bundle update --bundler also runs into the same error?

@rcaught
Copy link

rcaught commented Jun 2, 2022

bundle update --bundler

Running this fixed it for me @deivid-rodriguez

issei-m added a commit to issei-m/rails_test_ar_relations that referenced this issue Jul 29, 2022
issei-m added a commit to issei-m/rails_test_ar_relations that referenced this issue Aug 4, 2022
@Keltz-dev
Copy link

Keltz-dev commented Aug 16, 2022

rm -rf Gemfile.lock
bundle install

Did the trick for me

@deivid-rodriguez
Copy link
Member

The recommended solution is

$ gem update --system
$ bundle update --bundler

What you did @Keltz-dev also works but note that all of your dependencies were also upgraded, since you regenerated the Gemfile.lock file from scratch.

@wilsoncelyCUC
Copy link

Thanks Guys. I just encountered the same issue

@FSuhas
Copy link

FSuhas commented Sep 20, 2022

Thanks Guys :)

edwardloveall added a commit to hotline-webring/hotline-webring that referenced this issue Jun 10, 2023
Without this, I was getting an error `uninitialized constant Gem::Source`. This thread suggested I update bundler and it totally fixed it:

rubygems/rubygems#5351 (comment)
edwardloveall added a commit to hotline-webring/hotline-webring that referenced this issue Jun 10, 2023
Without this, I was getting an error `uninitialized constant
Gem::Source`. This thread suggested I update bundler and it totally
fixed it:

rubygems/rubygems#5351 (comment)
edwardloveall added a commit to hotline-webring/hotline-webring that referenced this issue Jun 10, 2023
Without this, I was getting an error `uninitialized constant
Gem::Source`. This thread suggested I update bundler and it totally
fixed it:

rubygems/rubygems#5351 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet