From 1428c1e9a855e6ca22cd1187dff6bbf7fa4c93cc Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Mon, 2 May 2016 17:59:22 -0400 Subject: [PATCH] DRb TimerIdConv cleanup https://bugzilla.redhat.com/show_bug.cgi?id=1321934 The TimerIdConv thread was not being terminated after a method ends. The TimerIdConv thread sleeps for a hour before it GC's the objects --- lib/miq_automation_engine/engine/miq_ae_method.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/miq_automation_engine/engine/miq_ae_method.rb b/lib/miq_automation_engine/engine/miq_ae_method.rb index 759af4a5541..43c72e80ad8 100644 --- a/lib/miq_automation_engine/engine/miq_ae_method.rb +++ b/lib/miq_automation_engine/engine/miq_ae_method.rb @@ -225,7 +225,7 @@ def self.ruby_method_runnable?(aem) def self.setup_drb_for_ruby_method require 'drb/timeridconv' - DRb.install_id_conv(DRb::TimerIdConv.new(drb_cache_timeout)) + @global_id_conv = DRb.install_id_conv(DRb::TimerIdConv.new(drb_cache_timeout)) drb_front = MiqAeMethodService::MiqAeServiceFront.new drb = DRb.start_service("druby://127.0.0.1:0", drb_front) end @@ -238,6 +238,12 @@ def self.teardown_drb_for_ruby_method DRb.stop_service # Set the ID conv to nil so that the cache can be GC'ed DRb.install_id_conv(nil) + # This hack was done to prevent ruby from leaking the + # TimerIdConv thread. + # https://bugs.ruby-lang.org/issues/12342 + holder = @global_id_conv.instance_variable_get('@holder') + holder.instance_variable_get('@keeper').try(:kill) if holder + @global_id_conv = nil end def self.invoke_inline_ruby(aem, obj, inputs)