From 6475487218f9dbe210f79e59b9b7c1be46f18280 Mon Sep 17 00:00:00 2001 From: luke Date: Fri, 26 Jan 2007 21:54:18 +0000 Subject: Fixing #423. Configurations now default to timing out after 30 seconds (tunable with configtimeout). This only happens for remote configurations, not local configs compiled using puppet. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2095 980ebf18-57e1-0310-9a29-db15c13687c0 --- lib/puppet/client/master.rb | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/puppet/client/master.rb b/lib/puppet/client/master.rb index 65bdbf19a..261119bfa 100644 --- a/lib/puppet/client/master.rb +++ b/lib/puppet/client/master.rb @@ -1,5 +1,6 @@ # The client for interacting with the puppetmaster config server. require 'sync' +require 'timeout' class Puppet::Client::MasterClient < Puppet::Client unless defined? @@sync @@ -22,6 +23,11 @@ class Puppet::Client::MasterClient < Puppet::Client ) Puppet.setdefaults(:puppetd, + :configtimeout => [30, + "How long the client should wait for the configuration to be retrieved + before considering it a failure. This can help reduce flapping if too + many clients contact the server at one time." + ], :reportserver => ["$server", "The server to which to send transaction reports." ], @@ -298,6 +304,19 @@ class Puppet::Client::MasterClient < Puppet::Client self.class.instance = self @running = false + + @timeout = Puppet[:configtimeout] + case @timeout + when String: + if @timeout =~ /^\d+$/ + @timeout = Integer(@timeout) + else + raise ArgumentError, "Configuration timeout must be an integer" + end + when Integer: # nothing + else + raise ArgumentError, "Configuration timeout must be an integer" + end end # Mark that we should restart. The Puppet module checks whether we're running, @@ -540,7 +559,14 @@ class Puppet::Client::MasterClient < Puppet::Client if @local return get_local_config(facts) else - return get_remote_config(facts) + begin + Timeout::timeout(@timeout) do + return get_remote_config(facts) + end + rescue Timeout::Error + Puppet.err "Configuration retrieval timed out" + return nil + end end end -- cgit