Skip to content

Instantly share code, notes, and snippets.

@fidothe
Created March 30, 2021 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fidothe/6808e10daf22affec8cc5376cb473644 to your computer and use it in GitHub Desktop.
Save fidothe/6808e10daf22affec8cc5376cb473644 to your computer and use it in GitHub Desktop.
An attempt to provide a minimal reproduction of a threading-related JRuby problem

While working on https://github.com/fidothe/saxon-rb I hit errors in production using a semi-experimental branch (https://github.com/fidothe/saxon-rb/tree/error-reporting) in a threaded XML-processing program.

The errors were the same NoMethodError: undefined method __jcreate_meta!' as in jruby/jruby#6160, and the program structure is almost identical save for some loading indirection thanks to the use of autoload.

I am running it in a CI-type environment where 20+ EC2 instances are spun up to process a large amount of data. Most, but not all, runs I'd have one instance's process crash with the error.

Creating an instance of the problem class (https://github.com/fidothe/saxon-rb/blob/error-reporting/lib/saxon/error_reporter.rb, EgClass in this reproduction case) on the main thread, rather than in the worker threads, has made the problem vanish entirely.

require 'java'
module TortuousExample
class EgClass
def self.setup
include java.lang.Comparable
end
attr_reader :val
def initialize(val)
self.class.setup
@val = val
end
def compareTo(other)
val <=> other.val
end
end
end
require 'thread'
require 'pathname'
module TortuousExample
autoload :EgClass, (Pathname.new(__FILE__)/'../tortuous-example-autoload.rb').realpath
end
(1..8).map {
Thread.new {
sleep 0.5
print "."
TortuousExample::EgClass.new(rand(100))
}
}.each(&:join)
puts ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment