diff options
author | Luke Kanies <luke@madstop.com> | 2007-11-23 19:57:31 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2007-11-23 19:57:31 -0600 |
commit | 3bf70316529a50f2da1419c5b2504d9f7d089540 (patch) | |
tree | b2b729c686c8f251c2fc26e86a39e29428858a62 /lib/puppet | |
parent | 0ebd99e821870437a355a7ae02006d232347c155 (diff) | |
download | puppet-3bf70316529a50f2da1419c5b2504d9f7d089540.tar.gz puppet-3bf70316529a50f2da1419c5b2504d9f7d089540.tar.xz puppet-3bf70316529a50f2da1419c5b2504d9f7d089540.zip |
Adding patch 20070926235454-6856b-079fc12a9b63d59afd59aa205bc8bfeb350b097a.patch from womble -- Recycle the connection if we're presented with an EPIPE
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/network/xmlrpc/client.rb | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/lib/puppet/network/xmlrpc/client.rb b/lib/puppet/network/xmlrpc/client.rb index 790a257bb..e2417120b 100644 --- a/lib/puppet/network/xmlrpc/client.rb +++ b/lib/puppet/network/xmlrpc/client.rb @@ -46,10 +46,6 @@ module Puppet::Network raise XMLRPCClientError, "Certificates were not trusted: %s" % detail rescue ::XMLRPC::FaultException => detail - #Puppet.err "Could not call %s.%s: %s" % - # [namespace, method, detail.faultString] - #raise XMLRPCClientError, - # "XMLRPC Error: %s" % detail.faultString raise XMLRPCClientError, detail.faultString rescue Errno::ECONNREFUSED => detail msg = "Could not connect to %s on port %s" % @@ -57,12 +53,16 @@ module Puppet::Network raise XMLRPCClientError, msg rescue SocketError => detail Puppet.err "Could not find server %s: %s" % - [@puppet_server, detail.to_s] + [@host, detail.to_s] error = XMLRPCClientError.new( - "Could not find server %s" % @puppet_server + "Could not find server %s" % @host ) error.set_backtrace detail.backtrace raise error + rescue Errno::EPIPE + Puppet.warning "Other end went away; restarting connection and retrying" + self.recycle_connection + retry rescue => detail Puppet.err "Could not call %s.%s: %s" % [namespace, method, detail.inspect] @@ -82,6 +82,9 @@ module Puppet::Network # Use cert information from a Puppet client to set up the http object. def cert_setup(client) + # Cache it for next time + @cert_client = client + unless FileTest.exists?(Puppet[:localcacert]) raise Puppet::SSLCertificates::Support::MissingCertificate, "Could not find ca certificate %s" % Puppet[:localcacert] @@ -124,13 +127,26 @@ module Puppet::Network hash[:Server], hash[:Path], hash[:Port], - hash[:HTTPProxyHost], # proxy_host - hash[:HTTPProxyPort], # proxy_port + hash[:HTTPProxyHost], + hash[:HTTPProxyPort], nil, # user nil, # password true, # use_ssl 120 # a two minute timeout, instead of 30 seconds ) + initialize_connection + end + + def initialize_connection + # Yes, this may well be redoing what the XMLRPC::Client constructor + # did, but sometimes it won't be, because of the occasional retry. + @http = Net::HTTP.new(@host, @port, @proxy_host, @proxy_port) + @http.use_ssl = @use_ssl if @use_ssl + @http.read_timeout = @timeout + @http.open_timeout = @timeout + + # We overwrite the uninitialized @http here with a cached one. + key = "%s:%s" % [@host, @port] # We overwrite the uninitialized @http here with a cached one. key = "%s%s" % [hash[:Server], hash[:Port]] @@ -141,6 +157,14 @@ module Puppet::Network end end + def recycle_connection + conn_key = "%s:%s" % [@host, @port] + @@http_cache.delete(conn_key) + + initialize_connection + cert_setup(@cert_client) + end + def start @http.start unless @http.started? end |