From 52c5c79edf287db6a54423d8cb777564ef453610 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 9 Jul 2011 17:02:41 -0700 Subject: [PATCH] Retry connection on Net::SSH::Disconnect [closes GH-313] --- lib/vagrant/ssh.rb | 7 ++++++- test/vagrant/ssh_test.rb | 7 ------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index d36870c6d..b12d03afc 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -76,7 +76,12 @@ module Vagrant session, options = @current_session if !session || options != opts - session = retryable(:tries => 5, :on => Errno::ECONNREFUSED) do + # The exceptions which are acceptable to retry on during + # attempts to connect to SSH + exceptions = [Errno::ECONNREFUSED, Net::SSH::Disconnect] + + # Connect to SSH and gather the session + session = retryable(:tries => 5, :on => exceptions) do connection = Net::SSH.start(env.config.ssh.host, env.config.ssh.username, opts.merge( :keys => [env.config.ssh.private_key_path], diff --git a/test/vagrant/ssh_test.rb b/test/vagrant/ssh_test.rb index ecd700354..a23c2a853 100644 --- a/test/vagrant/ssh_test.rb +++ b/test/vagrant/ssh_test.rb @@ -203,13 +203,6 @@ class SshTest < Test::Unit::TestCase } end - should "return false if the connection is dropped" do - Net::SSH.expects(:start).raises(Net::SSH::Disconnect) - assert_nothing_raised { - assert !@ssh.up? - } - end - should "specifity the timeout as an option to execute" do @ssh.expects(:execute).yields(true).with() do |opts| assert_equal @env.config.ssh.timeout, opts[:timeout]