Skip to content

Commit

Permalink
Showing 2 changed files with 0 additions and 51 deletions.
25 changes: 0 additions & 25 deletions core/src/main/ruby/jruby/jruby.rb
Original file line number Diff line number Diff line change
@@ -44,31 +44,6 @@ def with_current_runtime_as_global
end
end

# cleanup the jars copied to the temp directory when it gets
# added to the JRuby classloader. when killing jruby hard
# then those files remain there as the JVM does not clean them
# up.
def cleanup_stale_tempfiles
Dir[File.join(ENV_JAVA['java.io.tmpdir'], 'jruby-*')].each do |dir|
pid = File.basename(dir)[6..-1]
unless process_exists?(pid)
# do not use fileutils here as we are in jruby-core
Dir[File.join(dir, '*')].each do |file|
File.delete(file) rescue warn "could not delete #{file}"
end
Dir.delete(dir) rescue warn "could not delete #{dir}"
end
end
end

def process_exists?(pid)
system("kill -0 #{pid} 2> /dev/null")
rescue
# i.e. windows
false
end
private :process_exists?

# Parse the given block or the provided content, returning a JRuby AST node.
def parse(content = nil, filename = (default_filename = true; '-'), extra_position_info = false, &block)
if block
26 changes: 0 additions & 26 deletions test/test_tempfile_cleanup.rb
Original file line number Diff line number Diff line change
@@ -15,32 +15,6 @@ def teardown
FileUtils.rm_f @tmpdir
end

def windows?
File.directory?("\\")
end

def test_cleanup_jars_from_jruby_class_loader
return if windows?
# run only in embedded case
skip unless ENV['RUBY']
cmd = ENV['RUBY'].sub(/^java/, 'java -Djruby.home=uri:classloader://META-INF/jruby.home') + ' -ropenssl -e "sleep(1230)"'
# with such a command it uses bash to start java
pid = Process.spawn(*cmd) + 1
# give jruby sometime to start
sleep 10

tmpfiles = File.join( ENV_JAVA['java.io.tmpdir'], "jruby-#{pid}", 'jruby*.jar' )
assert Dir[tmpfiles].size > 0

#Process.kill(9, pid)
system("kill -9 #{pid}")
sleep 1

JRuby.cleanup_stale_tempfiles

assert Dir[tmpfiles].size == 0
end

def test_cleanup
10.times { Tempfile.open('blah', @tmpdir) }

0 comments on commit 7f30455

Please sign in to comment.