summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-11-03 13:13:37 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2015-11-04 08:01:36 -0800
commitbaefdba8fb1a82fc808824cb828638385e9d873b (patch)
treea1cd710481c8a3a290a093052c8a6b4d9f53c518
parent40db8612b99c177ea24b181cbb0bf849f4748601 (diff)
downloadchef-lcg/lazy-socketless-require.tar.gz
thread-safe performant lazy requirelcg/lazy-socketless-require
-rw-r--r--lib/chef/http.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/chef/http.rb b/lib/chef/http.rb
index 8fa2569190..0d0abdddd8 100644
--- a/lib/chef/http.rb
+++ b/lib/chef/http.rb
@@ -200,7 +200,11 @@ class Chef
# PERFORMANCE CRITICAL: *MUST* lazy require here otherwise we load up webrick
# via chef-zero and that hits DNS (at *require* time) which may timeout,
# when for most knife/chef-client work we never need/want this loaded.
- require 'chef/http/socketless_chef_zero_client'
+ Thread.exclusive {
+ unless defined?(SocketlessChefZeroClient)
+ require 'chef/http/socketless_chef_zero_client'
+ end
+ }
SocketlessChefZeroClient.new(base_url)
else
BasicClient.new(base_url, :ssl_policy => Chef::HTTP::APISSLPolicy)