Skip to content

Commit

Permalink
fix #7489 preventing winrm connection leakage
Browse files Browse the repository at this point in the history
  • Loading branch information
mwrock committed Aug 13, 2016
1 parent c543867 commit 64828f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions plugins/communicators/winrm/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ def initialize(host, port, config)
def powershell(command, &block)
# Ensure an exit code
command += "\r\nif ($?) { exit 0 } else { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } }"
execute_with_rescue(executor.method("run_powershell_script"), command, &block)
session.create_executor do |executor|
execute_with_rescue(executor.method("run_powershell_script"), command, &block)
end
end

def cmd(command, &block)
execute_with_rescue(executor.method("run_cmd"), command, &block)
session.create_executor do |executor|
execute_with_rescue(executor.method("run_cmd"), command, &block)
end
end

def wql(query, &block)
Expand Down Expand Up @@ -172,10 +176,6 @@ def session
@session ||= new_session
end

def executor
@executor ||= session.create_executor
end

def endpoint
case @config.transport.to_sym
when :ssl
Expand Down
4 changes: 3 additions & 1 deletion test/unit/plugins/communicators/winrm/shell_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
describe VagrantPlugins::CommunicatorWinRM::WinRMShell do
include_context "unit"

let(:session) { double("winrm_session", create_executor: executor) }
let(:session) { double("winrm_session") }
let(:executor) { double("command_executor") }
let(:port) { config.transport == :ssl ? 5986 : 5985 }
let(:config) {
Expand All @@ -22,6 +22,8 @@
end
}

before { allow(session).to receive(:create_executor).and_yield(executor) }

subject do
described_class.new('localhost', port, config).tap do |comm|
allow(comm).to receive(:new_session).and_return(session)
Expand Down

0 comments on commit 64828f1

Please sign in to comment.