core: retry SSH keygen on RSAError [GH-5056]

/cc @sethvargo
This commit is contained in:
Mitchell Hashimoto 2015-07-06 14:44:23 -06:00
parent bb25bb3be9
commit 79115d1ccc
2 changed files with 12 additions and 1 deletions

View File

@ -49,6 +49,7 @@ BUG FIXES:
- core: Only take files when packaging a box to avoid duplicates [GH-5658, GH-5657] - core: Only take files when packaging a box to avoid duplicates [GH-5658, GH-5657]
- core: escape curl urls and authentication [GH-5677] - core: escape curl urls and authentication [GH-5677]
- core: fix crash if a value is missing for CLI arguments [GH-5550] - 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/cli: fix box checksum validation [GH-4665, GH-5221]
- core/windows: allow Windows UNC paths to allow more than 256 - core/windows: allow Windows UNC paths to allow more than 256
characters [GH-4815] characters [GH-4815]

View File

@ -1,9 +1,13 @@
require "base64" require "base64"
require "openssl" require "openssl"
require "vagrant/util/retryable"
module Vagrant module Vagrant
module Util module Util
class Keypair class Keypair
extend Retryable
# Creates an SSH keypair and returns it. # Creates an SSH keypair and returns it.
# #
# @param [String] password Password for the key, or nil for no password. # @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 # respectively. The final element is the OpenSSH encoded public
# key. # key.
def self.create(password=nil) 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 public_key = rsa_key.public_key
private_key = rsa_key.to_pem private_key = rsa_key.to_pem