Sha256: f765b92b6fbb74fb377d45209f73736d22361b886711acfe219472c9273855ec

Contents?: true

Size: 1.1 KB

Versions: 14

Compression:

Stored size: 1.1 KB

Contents

require 'capistrano/configuration'

# Overrides a method in Capistrano::Configurations::Connections that has multiple threads writing to a shared hash.
# While that shared hash is a thread local variable, the thread is passed as an argument, so all the connection
# threads are trying to update it at the same time.  This has been observed to cause problems where servers will end
# up losing their connection objects, messing up all future SSH operations and eventually leading to an error about
# calling a method on a nil object.
#
# We shouldn't make a habit of patching Capistrano in Rubber. But since Capistrano 2.x is effectively a dead project,
# getting this fixed upstream is extremely unlikely.

module Capistrano
  class Configuration
    private

    MUTEX = Mutex.new

    def safely_establish_connection_to(server, thread, failures=nil)
      MUTEX.synchronize do
        thread[:sessions] ||= {}
        thread[:sessions][server] ||= connection_factory.connect_to(server)
      end
    rescue Exception => err
      raise unless failures
      failures << { :server => server, :error => err }
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rubber-3.2.2 lib/capistrano/thread_safety_fix.rb
rubber-3.2.1 lib/capistrano/thread_safety_fix.rb
rubber-3.2.0 lib/capistrano/thread_safety_fix.rb
rubber-3.1.0 lib/capistrano/thread_safety_fix.rb
rubber-3.0.1 lib/capistrano/thread_safety_fix.rb
rubber-3.0.0 lib/capistrano/thread_safety_fix.rb
rubber-2.16.0 lib/capistrano/thread_safety_fix.rb
rubber-2.15.2 lib/capistrano/thread_safety_fix.rb
rubber-2.15.1 lib/capistrano/thread_safety_fix.rb
rubber-2.15.0 lib/capistrano/thread_safety_fix.rb
rubber-2.14.0 lib/capistrano/thread_safety_fix.rb
rubber-2.13.1 lib/capistrano/thread_safety_fix.rb
rubber-2.13.0 lib/capistrano/thread_safety_fix.rb
rubber-2.12.2 lib/capistrano/thread_safety_fix.rb