From 5dbe563d143c1b2e68d8ef8ebcd0ad8dab4fc628 Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Wed, 16 Nov 2011 13:40:55 -0500 Subject: [PATCH] RUBY-364 --- lib/mongo/util/core_ext.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/mongo/util/core_ext.rb b/lib/mongo/util/core_ext.rb index 4899d0a..78ca0d7 100644 --- a/lib/mongo/util/core_ext.rb +++ b/lib/mongo/util/core_ext.rb @@ -83,3 +83,23 @@ class Class end end end + +# Fix a bug in the interaction of +# mutexes and timeouts in Ruby 1.9. +# See https://jira.mongodb.org/browse/RUBY-364 for details. +if RUBY_VERSION > '1.9' + class Mutex + def lock_with_hack + lock_without_hack + rescue ThreadError => e + if e.message != "deadlock; recursive locking" + raise + else + unlock + lock_without_hack + end + end + alias_method :lock_without_hack, :lock + alias_method :lock, :lock_with_hack + end +end