Skip to content

Commit bdbd841

Browse files
committed
Make cache and values fully thread-safe
Not locking the default initialization can lead to race-conditions. ref: ruby-concurrency/concurrent-ruby#970 Co-authored-by: Maciej Mensfeld <[email protected]> resolves puppetlabs#8951
1 parent d3caef9 commit bdbd841

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/puppet/settings.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ def initialize
146146
@configuration_file = nil
147147

148148
# And keep a per-environment cache
149-
@cache = Concurrent::Hash.new { |hash, key| hash[key] = Concurrent::Hash.new }
150-
@values = Concurrent::Hash.new { |hash, key| hash[key] = Concurrent::Hash.new }
149+
@cache = Concurrent::Hash.new { |hash, key| hash.compute_if_absent(key) { Concurrent::Hash.new } }
150+
@values = Concurrent::Hash.new { |hash, key| hash.compute_if_absent(key) { Concurrent::Hash.new } }
151151

152152
# The list of sections we've used.
153153
@used = []

0 commit comments

Comments
 (0)