ruby-amqp/bunny — Issue #42: Timeout after SSL handshake
Author: Fitzsimmons
Created: 2012-02-28 16:59:40+00:00
State: open

The following hello-world style test cases were run in the same environment:

```ruby
require 'rubygems'
require 'bunny'

b = Bunny.new("amqps://marysue")
b.start
q = b.queue("ssl_test")
e = b.exchange('')
e.publish("Bunny", :key => "ssl_test")

message = q.pop
puts "Received a message: #{message[:payload]}. Disconnecting..."

b.stop
```

and

```ruby
require "rubygems"
require "amqp"

EventMachine.run do
connection = AMQP.connect('amqps://marysue')
channel = AMQP::Channel.new(connection)
queue = channel.queue("ssl_test")
exchange = channel.default_exchange
exchange.publish "ruby-amqp", :routing_key => queue.name

queue.subscribe do |payload|
puts "Received a message: #{payload}. Disconnecting..."

connection.close {
EventMachine.stop { exit }
}
end
end
```

The bunny example fails with the following exception:

```bunny-0.8.0.pre1/lib/bunny/client.rb:165:in `open_connection': Connection failed - user: guest (Bunny::ProtocolError)```

Which I believe is actually a timeout error, since program freezes for several seconds before finally crashing. The program completes successfully if :ssl => true is removed from the connection line.

The following is the rabbitmq server log pertaining to the failing bunny connection:

```
=INFO REPORT==== 28-Feb-2012::11:49:57 ===
accepted TCP connection on [::]:5671 from 127.0.0.1:50850

=INFO REPORT==== 28-Feb-2012::11:49:57 ===
starting TCP connection <0.457.0> from 127.0.0.1:50850

=INFO REPORT==== 28-Feb-2012::11:49:57 ===
upgraded TCP connection <0.457.0> to SSL

=ERROR REPORT==== 28-Feb-2012::11:50:07 ===
exception on TCP connection <0.457.0> from 127.0.0.1:50850
{handshake_timeout,frame_header}

=INFO REPORT==== 28-Feb-2012::11:50:07 ===
closing TCP connection <0.457.0> from 127.0.0.1:50850
```

In comparison, here is the log entry from the successful amqp gem

```
=INFO REPORT==== 28-Feb-2012::11:51:31 ===
accepted TCP connection on [::]:5671 from 127.0.0.1:50891

=INFO REPORT==== 28-Feb-2012::11:51:31 ===
starting TCP connection <0.319.0> from 127.0.0.1:50891

=INFO REPORT==== 28-Feb-2012::11:51:31 ===
upgraded TCP connection <0.319.0> to SSL

=INFO REPORT==== 28-Feb-2012::11:51:31 ===
closing TCP connection <0.319.0> from 127.0.0.1:50891
```

For reference, marysue is simply the hostname of my local computer, for which I generated the certificate. The address resolves to 127.0.0.1