From 8096de651bf3cac85684751455d1e9b615533b5c Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Mon, 10 Jun 2024 03:45:30 +0900 Subject: [PATCH] Create thread in shell finalizer (#339) --- lib/winrm/shells/base.rb | 4 ++++ lib/winrm/shells/cmd.rb | 4 ---- lib/winrm/shells/power_shell.rb | 4 ---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/winrm/shells/base.rb b/lib/winrm/shells/base.rb index 7bb86637..3d11ac49 100644 --- a/lib/winrm/shells/base.rb +++ b/lib/winrm/shells/base.rb @@ -183,6 +183,10 @@ def add_finalizer def remove_finalizer ObjectSpace.undefine_finalizer(self) end + + def self.finalize(connection_opts, transport, shell_id) + proc { Thread.new { close_shell(connection_opts, transport, shell_id) } } + end end end end diff --git a/lib/winrm/shells/cmd.rb b/lib/winrm/shells/cmd.rb index d32dd665..07ff8a92 100644 --- a/lib/winrm/shells/cmd.rb +++ b/lib/winrm/shells/cmd.rb @@ -20,10 +20,6 @@ module Shells class Cmd < Base include WinRM::WSMV::SOAP class << self - def finalize(connection_opts, transport, shell_id) - proc { Cmd.close_shell(connection_opts, transport, shell_id) } - end - def close_shell(connection_opts, transport, shell_id) msg = WinRM::WSMV::CloseShell.new(connection_opts, shell_id: shell_id) transport.send_request(msg.build) diff --git a/lib/winrm/shells/power_shell.rb b/lib/winrm/shells/power_shell.rb index d9ca50d2..696ede9f 100644 --- a/lib/winrm/shells/power_shell.rb +++ b/lib/winrm/shells/power_shell.rb @@ -29,10 +29,6 @@ class Powershell < Base include WinRM::WSMV::SOAP class << self - def finalize(connection_opts, transport, shell_id) - proc { Powershell.close_shell(connection_opts, transport, shell_id) } - end - def close_shell(connection_opts, transport, shell_id) msg = WinRM::WSMV::CloseShell.new( connection_opts,