summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Azuma <dazuma@gmail.com>2009-09-02 10:25:45 -0700
committerDaniel Azuma <dazuma@gmail.com>2009-09-02 10:25:45 -0700
commitfd3cb2fe0b128fed2def2bd3e9957d473a9c879c (patch)
treec2bde46c31f5422ebb5ed59d90e5ccc462271bdd
parentbe5992144d5da73db835ac9601c53edb0b5d4e0a (diff)
downloadnet-ssh-issue-1.tar.gz
Scale back IO#select patch so it mutexes only zero-timeout callsissue-1
-rw-r--r--lib/net/ssh/ruby_compat.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/net/ssh/ruby_compat.rb b/lib/net/ssh/ruby_compat.rb
index 2fa2a9b..8a1c8f2 100644
--- a/lib/net/ssh/ruby_compat.rb
+++ b/lib/net/ssh/ruby_compat.rb
@@ -14,9 +14,9 @@ module Net; module SSH
# for different ruby implementations.
class Compat
- # A workaround for an IO#select threading bug in MRI 1.8.
+ # A workaround for an IO#select threading bug in certain versions of MRI 1.8.
# See: http://net-ssh.lighthouseapp.com/projects/36253/tickets/1-ioselect-threading-bug-in-ruby-18
- # Also: http://redmine.ruby-lang.org/issues/show/1993
+ # The root issue is documented here: http://redmine.ruby-lang.org/issues/show/1993
if RUBY_VERSION >= '1.9' || RUBY_PLATFORM == 'java'
def self.io_select(*params)
IO.select(*params)
@@ -24,7 +24,15 @@ module Net; module SSH
else
SELECT_MUTEX = Mutex.new
def self.io_select(*params)
- SELECT_MUTEX.synchronize do
+ # It should be safe to wrap calls in a mutex when the timeout is 0
+ # (that is, the call is not supposed to block).
+ # We leave blocking calls unprotected to avoid causing deadlocks.
+ # This should still catch the main case for Capistrano users.
+ if params[3] == 0
+ SELECT_MUTEX.synchronize do
+ IO.select(*params)
+ end
+ else
IO.select(*params)
end
end