Permalink
Browse files

Don't let nested mutex deadlock the thread.

  • Loading branch information...
1 parent 0d48d70 commit 1aed2d1b173e03646a5c79c82e4be052c08e86cc @technoweenie committed Dec 28, 2012
Showing with 6 additions and 1 deletion.
  1. +6 −1 lib/faraday.rb
View
@@ -181,7 +181,12 @@ def lookup_middleware(key)
end
def middleware_mutex(&block)
- (@middleware_mutex ||= Mutex.new).synchronize(&block)
+ @middleware_mutex ||= Mutex.new
+ if @middleware_mutex.locked?
+ block.call
+ else
+ @middleware_mutex.synchronize(&block)
+ end
end
def fetch_middleware(key)

0 comments on commit 1aed2d1

Please sign in to comment.