Skip to content

Commit

Permalink
RUBY-3604 Fix multithread auth race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
jteich committed Dec 23, 2024
1 parent 6e62448 commit f145618
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/mongo/auth/credential_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -47,7 +52,9 @@ class << self
end

module_function def clear
@store = {}
MUTEX.synchronize do
@store = {}
end
end
end
end
Expand Down

0 comments on commit f145618

Please sign in to comment.