Skip to content

Commit

Permalink
fix: Avoid lazy-initialized lock (#1577)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleolleolle authored Jul 31, 2024
1 parent 4860f75 commit 051a635
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/faraday/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Middleware
attr_reader :app, :options

DEFAULT_OPTIONS = {}.freeze
LOCK = Mutex.new

def initialize(app = nil, options = {})
@app = app
Expand All @@ -27,7 +28,7 @@ class << self
#
def default_options=(options = {})
validate_default_options(options)
lock.synchronize do
LOCK.synchronize do
@default_options = default_options.merge(options)
end
end
Expand All @@ -41,10 +42,6 @@ def default_options

private

def lock
@lock ||= Monitor.new
end

def validate_default_options(options)
invalid_keys = options.keys.reject { |opt| self::DEFAULT_OPTIONS.key?(opt) }
return unless invalid_keys.any?
Expand Down

0 comments on commit 051a635

Please sign in to comment.