diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index e83497aba..8bfc8b3cd 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -162,6 +162,8 @@ module Vagrant # in order to provide basic command error checking while still # providing access to the actual session object. class Session + include Util::Retryable + attr_reader :session def initialize(session) @@ -184,9 +186,7 @@ module Vagrant ch[:result] << data if [:stdout, :stderr].include?(type) end - tries = 5 - - begin + retryable(:tries => 5, :on => IOError, :sleep => 0.5) do metach = session.open_channel do |channel| channel.exec(command) do |ch, success| raise "could not execute command: #{command.inspect}" unless success @@ -207,13 +207,10 @@ module Vagrant end end end - rescue IOError - retry if (tries -= 1) > 0 - raise - end - metach.wait - metach[:result] + metach.wait + metach[:result] + end end # Checks for an erroroneous exit status and raises an exception diff --git a/lib/vagrant/util/retryable.rb b/lib/vagrant/util/retryable.rb index 2247cfe42..04f2ec043 100644 --- a/lib/vagrant/util/retryable.rb +++ b/lib/vagrant/util/retryable.rb @@ -13,7 +13,10 @@ module Vagrant begin return yield rescue opts[:on] - retry if (opts[:tries] -= 1) > 0 + if (opts[:tries] -= 1) > 0 + sleep opts[:sleep].to_f if opts[:sleep] + retry + end raise end end