diff --git a/lib/krane/resource_cache.rb b/lib/krane/resource_cache.rb index baba9f8a8..87d0a87a4 100644 --- a/lib/krane/resource_cache.rb +++ b/lib/krane/resource_cache.rb @@ -8,8 +8,13 @@ class ResourceCache def initialize(task_config) @task_config = task_config - - @kind_fetcher_locks = Concurrent::Hash.new { |hash, key| hash[key] = Mutex.new } + @mutex = Mutex.new + @kind_fetcher_locks = Concurrent::Hash.new do |hash, key| + @mutex.synchronize do + break hash[key] if hash.key?(key) + hash[key] = Mutex.new + end + end @data = Concurrent::Hash.new @kubectl = Kubectl.new(task_config: @task_config, log_failure_by_default: false) end