Wrap the transport connection in a mutex, this works around a deadlock in multi-threaded situations. See #894

git-svn-id: file:///home/svn/framework3/trunk@8568 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2010-02-20 15:19:24 +00:00
parent 445676b932
commit 94befada32
1 changed files with 9 additions and 4 deletions

View File

@ -1,7 +1,7 @@
require 'rex/socket'
# Monkeypatch rex/socket so Net::SSH's calls to TCPSocket.open and
# TCPSocket.new work when they're sent instead to
# TCPSocket.new work when they're sent instead to
# Rex::Socket::Tcp.connect
module Rex::Socket::Tcp
@ -134,7 +134,7 @@ module Net
# host to a known_hosts dictionary file
# * :host_name => the real host name or IP to log into. This is used
# instead of the +host+ parameter, and is primarily only useful when
# specified in an SSH configuration file. It lets you specify an
# specified in an SSH configuration file. It lets you specify an
# "alias", similarly to adding an entry in /etc/hosts but without needing
# to modify /etc/hosts.
# * :kex => the key exchange algorithm (or algorithms) to use
@ -193,7 +193,11 @@ module Net
end
end
transport = Transport::Session.new(host, options)
transport = nil
(@@mutex ||= ::Mutex.new).synchronize do
transport = Transport::Session.new(host, options)
end
auth = Authentication::Session.new(transport, options)
user = options.fetch(:user, user)
@ -226,8 +230,9 @@ module Net
when false, nil then return {}
else Array(use_ssh_config)
end
Net::SSH::Config.for(host, files)
end
end
end