Skip to content

Instantly share code, notes, and snippets.

@bbrowning
Created August 4, 2015 15:23
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 bbrowning/3cbb3901d4facd7fc99f to your computer and use it in GitHub Desktop.
Save bbrowning/3cbb3901d4facd7fc99f to your computer and use it in GitHub Desktop.
num_runtimes = 10
puts "Creating runtimes..."
num_runtimes.times do
instance = org.jruby.Ruby.newInstance
instance.evalScriptlet <<-EOS
require "socket"
server = TCPServer.new(0)
Thread.new do
begin
server.accept
rescue Exception => ex
end
end
Thread.new do
sleep 1
JRuby.runtime.tearDown(false)
end
EOS
end
puts "Waiting for runtimes to teardown..."
sleep 5
mbean = java.lang.management.ManagementFactory.getThreadMXBean
threads = mbean.getThreadInfo(mbean.getAllThreadIds)
thread_names = threads.map(&:thread_name)
leaked_runtimes = thread_names.select do |name|
name =~ /Ruby-\d+-Thread-\d+/
end
puts "Created #{num_runtimes} JRuby runtimes and #{leaked_runtimes.size} " +
"leaked waiting on a selector"
exit 1 if leaked_runtimes.size > 0
# JRuby 1.7.21
$ jruby jruby_selector_leak.rb
Creating runtimes...
Waiting for runtimes to teardown...
Created 10 JRuby runtimes and 10 leaked waiting on a selector
# JRuby 9.0.0.0
$ jruby jruby_selector_leak.rb
Creating runtimes...
Waiting for runtimes to teardown...
Created 10 JRuby runtimes and 10 leaked waiting on a selector
# JRuby 9.0.1.0-SNAPSHOT + selector leak patch
$ jruby jruby_selector_leak.rb
Creating runtimes...
Waiting for runtimes to teardown...
Created 10 JRuby runtimes and 0 leaked waiting on a selector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment