Skip to content

Commit 727a097

Browse files
author
Christopher Brown
committed
PL-433 retry on 500 concurrency fixes
2 parents 9f94b3f + 794611d commit 727a097

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

‎chef/lib/chef/config.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def self.manage_secret_key
100100

101101
authorized_openid_identifiersnil
102102
authorized_openid_providersnil
103+
client_registration_retries5
103104
cookbook_path["/var/chef/cookbooks","/var/chef/site-cookbooks"]
104105
cookbook_tarball_path"/var/chef/cookbook-tarballs"
105106
couchdb_database"chef"

‎chef/lib/chef/rest.rb‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,29 @@ def load_signing_key(key)
6666

6767
# Register the client
6868
defregister(name=Chef::Config[:node_name],destination=Chef::Config[:client_key])
69-
70-
ifFile.exists?(destination)
71-
raiseChef::Exceptions::CannotWritePrivateKey,"I cannot write your private key to #{destination} - check permissions?"unlessFile.writable?(destination)
72-
end
69+
raiseChef::Exceptions::CannotWritePrivateKey,"I cannot write your private key to #{destination} - check permissions?"if(File.exists?(destination) && !File.writable?(destination))
7370

7471
nc=Chef::ApiClient.new
7572
nc.name(name)
76-
response=nc.save(true,true)
77-
78-
Chef::Log.debug("Registration response: #{response.inspect}")
79-
80-
raiseChef::Exceptions::CannotWritePrivateKey,"The response from the server did not include a private key!"unlessresponse.has_key?("private_key")
8173

82-
begin
83-
# Write out the private key
84-
file=File.open(destination,File::WRONLY|File::EXCL|File::CREAT,0600)
85-
file.print(response["private_key"])
86-
file.close
87-
rescue
88-
raiseChef::Exceptions::CannotWritePrivateKey,"I cannot write your private key to #{destination}"
74+
catch(:done)do
75+
retries=Chef::Config[:client_registration_retries] || 5
76+
retries.downto(0)do
77+
begin
78+
response=nc.save(true,true)
79+
Chef::Log.debug("Registration response: #{response.inspect}")
80+
raiseChef::Exceptions::CannotWritePrivateKey,"The response from the server did not include a private key!"unlessresponse.has_key?("private_key")
81+
# Write out the private key
82+
file=File.open(destination,"w")
83+
file.print(response["private_key"])
84+
file.close
85+
throw:done
86+
rescueIOError
87+
raiseChef::Exceptions::CannotWritePrivateKey,"I cannot write your private key to #{destination}"
88+
rescueNet::HTTPFatalError=>e
89+
raiseunlesse.response.code == "500"
90+
end
91+
end
8992
end
9093

9194
true

0 commit comments

Comments
(0)