Sha256: d0b28921c2b41cb5717f80cf8f355956d8b333e1702db95ae74d1819da7bec85

Contents?: true

Size: 1.12 KB

Versions: 19

Compression:

Stored size: 1.12 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, they 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)
      conn = connection_factory.connect_to(server)

      MUTEX.synchronize do
        thread[:sessions] ||= {}
        thread[:sessions][server] ||= conn
      end
    rescue Exception => err
      raise unless failures
      failures << { :server => server, :error => err }
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
rubber-2.12.1 lib/capistrano/thread_safety_fix.rb
rubber-2.12.0 lib/capistrano/thread_safety_fix.rb
rubber-2.11.0 lib/capistrano/thread_safety_fix.rb
rubber-2.10.2 lib/capistrano/thread_safety_fix.rb
rubber-2.10.1 lib/capistrano/thread_safety_fix.rb
rubber-2.10.0 lib/capistrano/thread_safety_fix.rb
rubber-2.9.0 lib/capistrano/thread_safety_fix.rb
rubber-2.8.1 lib/capistrano/thread_safety_fix.rb
rubber-2.8.0 lib/capistrano/thread_safety_fix.rb
rubber-2.7.5 lib/capistrano/thread_safety_fix.rb
rubber-2.7.4 lib/capistrano/thread_safety_fix.rb
rubber-2.7.3 lib/capistrano/thread_safety_fix.rb
rubber-2.7.2 lib/capistrano/thread_safety_fix.rb
rubber-2.7.1 lib/capistrano/thread_safety_fix.rb
rubber-2.7.0 lib/capistrano/thread_safety_fix.rb
rubber-2.6.5 lib/capistrano/thread_safety_fix.rb
rubber-2.6.4 lib/capistrano/thread_safety_fix.rb
rubber-2.6.3 lib/capistrano/thread_safety_fix.rb
rubber-2.6.2 lib/capistrano/thread_safety_fix.rb