diff --git a/lib/bunny/exceptions.rb b/lib/bunny/exceptions.rb index 229926c3f..74e50dbb5 100644 --- a/lib/bunny/exceptions.rb +++ b/lib/bunny/exceptions.rb @@ -65,7 +65,7 @@ def initialize(message, connection, connection_close = nil) class TCPConnectionFailed < Exception attr_reader :hostname, :port - def initialize(e, hostname, port) + def initialize(e, hostname=nil, port=nil) m = case e when String then e diff --git a/lib/bunny/session.rb b/lib/bunny/session.rb index 3258efe0d..f4e498953 100644 --- a/lib/bunny/session.rb +++ b/lib/bunny/session.rb @@ -285,7 +285,7 @@ def start @logger.warn "Retrying connection on next host in line: #{@transport.host}:#{@transport.port}" return self.start - rescue Exception + rescue @status_mutex.synchronize { @status = :not_connected } raise end @@ -961,13 +961,11 @@ def open_connection fr # frame timeout means the broker has closed the TCP connection, which it # does per 0.9.1 spec. - rescue Errno::ECONNRESET, ClientTimeout, AMQ::Protocol::EmptyResponseError, EOFError, IOError => e + rescue nil end if frame.nil? - @state = :closed - @logger.error "RabbitMQ closed TCP connection before AMQP 0.9.1 connection was finalized. Most likely this means authentication failure." - raise Bunny::PossibleAuthenticationFailureError.new(self.user, self.vhost, self.password.size) + raise TCPConnectionFailed.new('An empty frame was received while opening the connection. In RabbitMQ <= 3.1 this could mean an authentication issue.') end response = frame.decode_payload @@ -1011,13 +1009,11 @@ def open_connection fr # frame timeout means the broker has closed the TCP connection, which it # does per 0.9.1 spec. - rescue Errno::ECONNRESET, ClientTimeout, AMQ::Protocol::EmptyResponseError, EOFError => e + rescue nil end if frame2.nil? - @state = :closed - @logger.warn "RabbitMQ closed TCP connection before AMQP 0.9.1 connection was finalized. Most likely this means authentication failure." - raise Bunny::PossibleAuthenticationFailureError.new(self.user, self.vhost, self.password.size) + raise TCPConnectionFailed.new('An empty frame was received while opening the connection. In RabbitMQ <= 3.1 this could mean an authentication issue.') end connection_open_ok = frame2.decode_payload