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,