Skip to content

Commit

Permalink
Create thread in shell finalizer (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
akihikodaki authored Jun 9, 2024
1 parent 3cb67d0 commit 8096de6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
4 changes: 4 additions & 0 deletions lib/winrm/shells/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions lib/winrm/shells/cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions lib/winrm/shells/power_shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8096de6

Please sign in to comment.