summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-09-05 15:08:20 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-09-05 15:08:20 -0700
commita49e90d34770e60e1310719a2ba0bf48d15296dc (patch)
tree41e9c1b248feb81fcf872bf7dfab4be5c2810f6f
parent478c06df2c65d5e54299e4dc94914432a2807faa (diff)
downloadchef-jk/multitenant-chef-client-support.tar.gz
Fix intermittent failure with multiple threads trying to stop()jk/multitenant-chef-client-support
-rw-r--r--lib/chef/local_mode.rb37
1 files changed, 20 insertions, 17 deletions
diff --git a/lib/chef/local_mode.rb b/lib/chef/local_mode.rb
index 5b1e4d43e2..99a7af12f2 100644
--- a/lib/chef/local_mode.rb
+++ b/lib/chef/local_mode.rb
@@ -87,6 +87,7 @@ class Chef
#
def initialize(config)
@config = config
+ @stop_mutex = Mutex.new
end
attr_reader :config
@@ -180,25 +181,27 @@ class Chef
# If chef_zero_server is non-nil, stop it and remove references to it.
def stop
- if @chef_zero_server
- @chef_zero_server.stop
- @chef_zero_server = nil
- end
- # Restore config
- if @saved_config
- # We are trying to be surgical with our restore, and only restore
- # values that we put there.
- [:chef_server_url, :chef_server_root, :organization].each do |key|
- # TODO give mixlib-config a better restore method that is willing
- # to delete keys that are not saved
- if @saved_config.has_key?(key)
- config[:chef_server_url] = @saved_config[key]
- else
- config.delete(key)
- end
+ @stop_mutex.synchronize do
+ if @chef_zero_server
+ @chef_zero_server.stop
+ @chef_zero_server = nil
end
+ # Restore config
+ if @saved_config
+ # We are trying to be surgical with our restore, and only restore
+ # values that we put there.
+ [:chef_server_url, :chef_server_root, :organization].each do |key|
+ # TODO give mixlib-config a better restore method that is willing
+ # to delete keys that are not saved
+ if @saved_config.has_key?(key)
+ config[:chef_server_url] = @saved_config[key]
+ else
+ config.delete(key)
+ end
+ end
- @saved_config = nil
+ @saved_config = nil
+ end
end
end