Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle consul_acl connection refused as a retry-able error #336

Merged
merged 4 commits into from
Nov 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/puppet/provider/consul_acl/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,29 @@ def self.list_resources(acl_api_token, port, hostname, protocol, tries)
path=uri.request_uri + "/list?token=#{acl_api_token}"
req = Net::HTTP::Get.new(path)
res = nil
res_code = nil

# retry Consul API query for ACLs, in case Consul has just started
(1..tries).each do |i|
unless i == 1
Puppet.debug("retrying Consul API query in #{i} seconds")
sleep i
end
res = http.request(req)
break if res.code == '200'

begin
res = http.request(req)
res_code = res.code
break if res_code == '200'
rescue Errno::ECONNREFUSED => exc
Puppet.debug("#{uri}/list?token=<redacted> #{exc.class} #{exc.message}")
res_code = exc.class.to_s
end
end

if res.code == '200'
if res_code == '200'
acls = JSON.parse(res.body)
else
Puppet.warning("Cannot retrieve ACLs: invalid return code #{res.code} uri: #{path} body: #{req.body}")
Puppet.warning("Cannot retrieve ACLs: invalid return code #{res_code} uri: #{path} body: #{req.body}")
return {}
end

Expand Down