Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7201

Show
Ignore:
Timestamp:
07/21/07 19:15:58 (1 year ago)
Author:
minam
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tools/capistrano/CHANGELOG

    r7194 r7201  
    11*SVN* 
     2 
     3* Added "synchronous_connect" setting to try and work around SFTP hangs for certain users [Jamis Buck] 
    24 
    35* Auto-require the SSH shell service, to avoid race conditions [Jamis Buck] 
  • tools/capistrano/lib/capistrano/configuration/connections.rb

    r7176 r7201  
    7171        failed_servers = [] 
    7272 
    73         # force the connection factory to be instantiated synchronously, 
    74         # otherwise we wind up with multiple gateway instances, because 
    75         # each connection is done in parallel. 
    76         connection_factory 
     73        # This attemps to work around the problem where SFTP uploads hang 
     74        # for some people. A bit of investigating seemed to reveal that the 
     75        # hang only occurred when the SSH connections were established async, 
     76        # so this setting allows people to at least work around the problem. 
     77        if fetch(:synchronous_connect, false) 
     78          logger.trace "synchronous_connect: true" 
     79          Array(servers).each { |server| safely_establish_connection_to(server, failed_servers) } 
     80        else 
     81          # force the connection factory to be instantiated synchronously, 
     82          # otherwise we wind up with multiple gateway instances, because 
     83          # each connection is done in parallel. 
     84          connection_factory 
    7785 
    78         threads = Array(servers).map { |server| establish_connection_to(server, failed_servers) } 
    79         threads.each { |t| t.join } 
     86          threads = Array(servers).map { |server| establish_connection_to(server, failed_servers) } 
     87          threads.each { |t| t.join } 
     88        end 
    8089 
    8190        if failed_servers.any? 
     
    137146        # variable if the thread just happens to take too long to start up. 
    138147        def establish_connection_to(server, failures=nil) 
    139           Thread.new do 
    140             begin 
    141               sessions[server] ||= connection_factory.connect_to(server) 
    142             rescue Exception => err 
    143               raise unless failures 
    144               failures << { :server => server, :error => err } 
    145             end 
    146           end 
     148          Thread.new { safely_establish_connection_to(server, failures) } 
     149        end 
     150 
     151        def safely_establish_connection_to(server, failures=nil) 
     152          sessions[server] ||= connection_factory.connect_to(server) 
     153        rescue Exception => err 
     154          raise unless failures 
     155          failures << { :server => server, :error => err } 
    147156        end 
    148157    end