diff --git a/lib/mongo/auth/credential_cache.rb b/lib/mongo/auth/credential_cache.rb index 16d7962775..32c2fd640b 100644 --- a/lib/mongo/auth/credential_cache.rb +++ b/lib/mongo/auth/credential_cache.rb @@ -22,19 +22,24 @@ module Auth # # @api private module CredentialCache + MUTEX = Mutex.new class << self attr_reader :store end module_function def get(key) - @store ||= {} - @store[key] + MUTEX.synchronize do + @store ||= {} + @store[key] + end end module_function def set(key, value) - @store ||= {} - @store[key] = value + MUTEX.synchronize do + @store ||= {} + @store[key] = value + end end module_function def cache(key) @@ -47,7 +52,9 @@ class << self end module_function def clear - @store = {} + MUTEX.synchronize do + @store = {} + end end end end