mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Add synchronous_connect option to force connections to be established synchronously, rather than in parallel, in an attempt to work around some reported SFTP upload hangs that appear to be related
git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@7201 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
01103e63ea
commit
8fd6e73a2d
2 changed files with 25 additions and 14 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Added "synchronous_connect" setting to try and work around SFTP hangs for certain users [Jamis Buck]
|
||||
|
||||
* Auto-require the SSH shell service, to avoid race conditions [Jamis Buck]
|
||||
|
||||
* Add a millisecond sleep in upload to reduce CPU impact [Jamis Buck]
|
||||
|
|
|
@ -70,13 +70,22 @@ module Capistrano
|
|||
def establish_connections_to(servers)
|
||||
failed_servers = []
|
||||
|
||||
# force the connection factory to be instantiated synchronously,
|
||||
# otherwise we wind up with multiple gateway instances, because
|
||||
# each connection is done in parallel.
|
||||
connection_factory
|
||||
# This attemps to work around the problem where SFTP uploads hang
|
||||
# for some people. A bit of investigating seemed to reveal that the
|
||||
# hang only occurred when the SSH connections were established async,
|
||||
# so this setting allows people to at least work around the problem.
|
||||
if fetch(:synchronous_connect, false)
|
||||
logger.trace "synchronous_connect: true"
|
||||
Array(servers).each { |server| safely_establish_connection_to(server, failed_servers) }
|
||||
else
|
||||
# force the connection factory to be instantiated synchronously,
|
||||
# otherwise we wind up with multiple gateway instances, because
|
||||
# each connection is done in parallel.
|
||||
connection_factory
|
||||
|
||||
threads = Array(servers).map { |server| establish_connection_to(server, failed_servers) }
|
||||
threads.each { |t| t.join }
|
||||
threads = Array(servers).map { |server| establish_connection_to(server, failed_servers) }
|
||||
threads.each { |t| t.join }
|
||||
end
|
||||
|
||||
if failed_servers.any?
|
||||
errors = failed_servers.map { |h| "#{h[:server]} (#{h[:error].class}: #{h[:error].message})" }
|
||||
|
@ -136,14 +145,14 @@ module Capistrano
|
|||
# prevents problems with the thread's scope seeing the wrong 'server'
|
||||
# variable if the thread just happens to take too long to start up.
|
||||
def establish_connection_to(server, failures=nil)
|
||||
Thread.new do
|
||||
begin
|
||||
sessions[server] ||= connection_factory.connect_to(server)
|
||||
rescue Exception => err
|
||||
raise unless failures
|
||||
failures << { :server => server, :error => err }
|
||||
end
|
||||
end
|
||||
Thread.new { safely_establish_connection_to(server, failures) }
|
||||
end
|
||||
|
||||
def safely_establish_connection_to(server, failures=nil)
|
||||
sessions[server] ||= connection_factory.connect_to(server)
|
||||
rescue Exception => err
|
||||
raise unless failures
|
||||
failures << { :server => server, :error => err }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue