From 79115d1ccc26cb4b3a2f375f88b44fc8df1bbffd Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 6 Jul 2015 14:44:23 -0600 Subject: [PATCH] core: retry SSH keygen on RSAError [GH-5056] /cc @sethvargo --- CHANGELOG.md | 1 + lib/vagrant/util/keypair.rb | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ada69624..6ca0cc41e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ BUG FIXES: - core: Only take files when packaging a box to avoid duplicates [GH-5658, GH-5657] - core: escape curl urls and authentication [GH-5677] - core: fix crash if a value is missing for CLI arguments [GH-5550] + - core: retry SSH key generation for transient RSA errors [GH-5056] - core/cli: fix box checksum validation [GH-4665, GH-5221] - core/windows: allow Windows UNC paths to allow more than 256 characters [GH-4815] diff --git a/lib/vagrant/util/keypair.rb b/lib/vagrant/util/keypair.rb index 7fec84b2a..342d3264f 100644 --- a/lib/vagrant/util/keypair.rb +++ b/lib/vagrant/util/keypair.rb @@ -1,9 +1,13 @@ require "base64" require "openssl" +require "vagrant/util/retryable" + module Vagrant module Util class Keypair + extend Retryable + # Creates an SSH keypair and returns it. # # @param [String] password Password for the key, or nil for no password. @@ -11,7 +15,13 @@ module Vagrant # respectively. The final element is the OpenSSH encoded public # key. def self.create(password=nil) - rsa_key = OpenSSL::PKey::RSA.new(2048) + # This sometimes fails with RSAError. It is inconsistent and strangely + # sleeps seem to fix it. We just retry this a few times. See GH-5056 + rsa_key = nil + retryable(on: OpenSSL::PKey::RSAError, sleep: 2, tries: 5) do + rsa_key = OpenSSL::PKey::RSA.new(2048) + end + public_key = rsa_key.public_key private_key = rsa_key.to_pem