Skip to content

autoload-ed constant sometimes fails #6293

@kares

Description

@kares

still haven't found a great way to reproduce but I managed to reproduce if I let this script loop for a while:

# from RubyGems :
#
#   autoload :Specification,      'rubygems/specification'
#
# suprisingly, rubygems.rb also explicitly requires after the autoload:
#
#    require "rubygems/specification" 
#

class Sample
  def self.spec
    Gem::Specification.dirs
  end
end

$lock = java.util.concurrent.atomic.AtomicBoolean.new
threads = []
30.times.each do
  threads << Thread.new {
    while ! $lock.get
      sleep 0.00001
    end
    Sample.spec
  }
end
sleep 0.5
$lock.set true

sleep 1.0

threads.each { |t| p t.value }
LAST=0
while [ $LAST -eq 0 ]; do
  jruby -v -Xcompile.invokedynamic=true -Xjit.threshold=0 gem_spec_dirs.rb
  LAST=$?
  echo "LAST: $LAST"
done

~40th iteration I finally reproduce the loading issue (also reproduces on 9.2.11.1):

jruby 9.2.7.0 (2.5.3) 2019-04-09 8a269e3 Java HotSpot(TM) 64-Bit Server VM 25.171-b11 on 1.8.0_171-b11 +indy +jit [linux-x86_64]
warning: thread "Ruby-0-Thread-14: gem_spec_dirs.rb:29" terminated with exception (report_on_exception is true):
["/opt/local/rvm/gems/jruby-9.2.7.0@ls/specifications", "/opt/local/rvm/gems/jruby-9.2.7.0@global/specifications"]
["/opt/local/rvm/gems/jruby-9.2.7.0@ls/specifications", "/opt/local/rvm/gems/jruby-9.2.7.0@global/specifications"]
["/opt/local/rvm/gems/jruby-9.2.7.0@ls/specifications", "/opt/local/rvm/gems/jruby-9.2.7.0@global/specifications"]
["/opt/local/rvm/gems/jruby-9.2.7.0@ls/specifications", "/opt/local/rvm/gems/jruby-9.2.7.0@global/specifications"]
["/opt/local/rvm/gems/jruby-9.2.7.0@ls/specifications", "/opt/local/rvm/gems/jruby-9.2.7.0@global/specifications"]
["/opt/local/rvm/gems/jruby-9.2.7.0@ls/specifications", "/opt/local/rvm/gems/jruby-9.2.7.0@global/specifications"]
["/opt/local/rvm/gems/jruby-9.2.7.0@ls/specifications", "/opt/local/rvm/gems/jruby-9.2.7.0@global/specifications"]
["/opt/local/rvm/gems/jruby-9.2.7.0@ls/specifications", "/opt/local/rvm/gems/jruby-9.2.7.0@global/specifications"]
["/opt/local/rvm/gems/jruby-9.2.7.0@ls/specifications", "/opt/local/rvm/gems/jruby-9.2.7.0@global/specifications"]
["/opt/local/rvm/gems/jruby-9.2.7.0@ls/specifications", "/opt/local/rvm/gems/jruby-9.2.7.0@global/specifications"]
["/opt/local/rvm/gems/jruby-9.2.7.0@ls/specifications", "/opt/local/rvm/gems/jruby-9.2.7.0@global/specifications"]
["/opt/local/rvm/gems/jruby-9.2.7.0@ls/specifications", "/opt/local/rvm/gems/jruby-9.2.7.0@global/specifications"]
["/opt/local/rvm/gems/jruby-9.2.7.0@ls/specifications", "/opt/local/rvm/gems/jruby-9.2.7.0@global/specifications"]
NameError: uninitialized constant Gem::Specification
Did you mean?  Gem::Specification
               Gem::StubSpecification
            const_missing at org/jruby/RubyModule.java:3742
                     spec at gem_spec_dirs.rb:32
  gem_spec_dirs.rb at gem_spec_dirs.rb:43
NameError: uninitialized constant Gem::Specification
Did you mean?  Gem::Specification
               Gem::StubSpecification
            const_missing at org/jruby/RubyModule.java:3742
                     spec at gem_spec_dirs.rb:32
gem_spec_dirs.rb at gem_spec_dirs.rb:43

NOTE: the Gem::Specification auto-loading part stayed the same between RGs 2.7.9 (JRuby 9.2.7.0) -> RGs 3.0.6 (9.2.11)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions