From 5691df37a15cc5f9066f61b9edd8983dd9f62b97 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 29 Aug 2012 13:39:03 -0700 Subject: [PATCH] Retry SSH on EHOSTUNREACH This is one of those errors that happens once in awhile that can be retried. --- CHANGELOG.md | 2 ++ plugins/communicators/ssh/communicator.rb | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94ac615fd..1644ddeca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,8 @@ "localhost" is not available. [GH-1057] - Sending a SIGINT (Ctrl-C) very early on when executing `vagrant` no longer results in an ugly stack trace. + - SSH retries in the face of a `EHOSTUNREACH` error, improving the robustness + that SSHing succeeds when booting a machine. ## 1.0.3 (May 1, 2012) diff --git a/plugins/communicators/ssh/communicator.rb b/plugins/communicators/ssh/communicator.rb index c268e3b34..55513759f 100644 --- a/plugins/communicators/ssh/communicator.rb +++ b/plugins/communicators/ssh/communicator.rb @@ -151,7 +151,16 @@ module VagrantPlugins # Connect to SSH, giving it a few tries connection = nil begin - exceptions = [Errno::ECONNREFUSED, Net::SSH::Disconnect, Timeout::Error] + # These are the exceptions that we retry because they represent + # errors that are generally fixed from a retry and don't + # necessarily represent immediate failure cases. + exceptions = [ + Errno::ECONNREFUSED, + Errno::EHOSTUNREACH, + Net::SSH::Disconnect, + Timeout::Error + ] + connection = retryable(:tries => @machine.config.ssh.max_tries, :on => exceptions) do Timeout.timeout(@machine.config.ssh.timeout) do @logger.info("Attempting to connect to SSH: #{ssh_info[:host]}:#{ssh_info[:port]}")