I see several errors from Bunny 2.7.0 in a multi-threaded Rails app in which background threads connect to RabbitMQ to exchange messages.
1. The threads can be from a thread pool (typically from concurrent-ruby).
2. Usually a single connection is shared and each task (running on a thread-pool thread) makes its own channel to talk to RabbitMQ.
3. Channels are closed in an exception-safe way using with_channel.
4. Most of the queues are RPC over AMQP type ephemeral queues. All are direct exchanges. There are also standard queues connected to these exchanges.
5. The maximum number of queues never reaches beyond 20. The maximum number of concurrent threads connected to MQ is never more than 20. The maximum number of messages on a queue is rarely beyond 10.
6. The Bunny sessions use a :heartbeat => :server option.
7. The RabbitMQ server runs with hipe_compile set to true. SSL is not used.
The following are the error stacks:
1. In Queue#subscribe:
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/concurrent/continuation_queue.rb:39:in `block in poll'
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/concurrent/continuation_queue.rb:30:in `synchronize'
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/concurrent/continuation_queue.rb:30:in `poll'
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/channel.rb:1761:in `wait_on_continuations'
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/channel.rb:920:in `block in basic_consume_with'
App 6423 stdout: /usr/share/ruby/timeout.rb:91:in `block in timeout'
App 6423 stdout: /usr/share/ruby/timeout.rb:101:in `call'
App 6423 stdout: /usr/share/ruby/timeout.rb:101:in `timeout'
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/channel.rb:919:in `basic_consume_with'
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/queue.rb:192:in `subscribe'
2. In Channel#close:
App 6423 stderr: 70122745671040 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/concurrent/continuation_queue.rb:39:in `block in poll'
App 6423 stderr: 70122745671040 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/concurrent/continuation_queue.rb:30:in `synchronize'
App 6423 stderr: 70122745671040 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/concurrent/continuation_queue.rb:30:in `poll'
App 6423 stderr: 70122745671040 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/session.rb:1318:in `wait_on_continuations'
App 6423 stderr: 70122745671040 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/session.rb:534:in `block in close_channel'
App 6423 stderr: 70122745671040 /usr/share/ruby/monitor.rb:211:in `mon_synchronize'
App 6423 stderr: 70122745671040 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/session.rb:530:in `close_channel'
App 6423 stderr: 70122745671040 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/channel.rb:236:in `close'
3. In Session#create_channel:
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/concurrent/continuation_queue.rb:39:in `block in poll'
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/concurrent/continuation_queue.rb:30:in `synchronize'
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/concurrent/continuation_queue.rb:30:in `poll'
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/session.rb:1318:in `wait_on_continuations'
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/session.rb:521:in `block in open_channel'
App 6423 stdout: /usr/share/ruby/monitor.rb:211:in `mon_synchronize'
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/session.rb:514:in `open_channel'
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/channel.rb:223:in `open'
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/session.rb:355:in `block in create_channel'
App 6423 stdout: /usr/share/ruby/monitor.rb:211:in `mon_synchronize'
App 6423 stdout: /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/session.rb:350:in `create_channel'
4. In Channel#queue:
App 6423 stderr: 70124403077420 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/concurrent/continuation_queue.rb:39:in `block in poll'
App 6423 stderr: 70124403077420 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/concurrent/continuation_queue.rb:30:in `synchronize'
App 6423 stderr: 70124403077420 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/concurrent/continuation_queue.rb:30:in `poll'
App 6423 stderr: 70124403077420 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/channel.rb:1761:in `wait_on_continuations'
App 6423 stderr: 70124403077420 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/channel.rb:1004:in `queue_declare'
App 6423 stderr: 70124403077420 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/queue.rb:370:in `declare!'
App 6423 stderr: 70124403077420 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/queue.rb:51:in `initialize'
App 6423 stderr: 70124403077420 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/channel.rb:413:in `new'
App 6423 stderr: 70124403077420 /usr/local/share/gems/gems/bunny-2.7.0/lib/bunny/channel.rb:413:in `queue'
Other errors seen:
A.
App 6423 stdout: W, [2017-06-21T07:55:21.500595 #6423] WARN -- #<Bunny::Session:0x64a5410 test@rmq:5672, vhost=/, addresses=[rmq:5672]>: Recovering from connection.close (CHANNEL_ERROR - second 'channel.open' seen)
App 6423 stdout: W, [2017-06-21T07:55:21.501245 #6423] WARN -- #<Bunny::Session:0x64a5410 test@rmq:5672, vhost=/, addresses=[rmq:5672]>: Will recover from a network failure (no retry limit)...
B.
App 6423 stdout: W, [2017-06-21T07:55:50.883476 #6423] WARN -- #<Bunny::Session:0x64a5410 test@rmq:5672, vhost=/, addresses=[rmq:5672]>: Retrying connection on next host in line: rmq:5672
C.
App 6423 stdout: E, [2017-06-21T07:55:55.115188 #6423] ERROR -- #<Bunny::Session:0x64a5410 test@rmq:5672, vhost=/, addresses=[rmq:5672]>: Got an exception when receiving data: Connection reset by peer (Errno::ECONNRESET)
App 6423 stdout: W, [2017-06-21T07:55:55.115378 #6423] WARN -- #<Bunny::Session:0x64a5410 test@rmq:5672, vhost=/, addresses=[rmq:5672]>: An empty frame was received while opening the connection. In RabbitMQ <= 3.1 this could mean an authentication issue.
App 6423 stdout: W, [2017-06-21T07:55:55.115495 #6423] WARN -- #<Bunny::Session:0x64a5410 test@rmq:5672, vhost=/, addresses=[rmq:5672]>: TCP connection failed, reconnecting in 5.0 seconds
App 6423 stdout: W, [2017-06-21T07:55:55.115535 #6423] WARN -- #<Bunny::Session:0x64a5410 test@rmq:5672, vhost=/, addresses=[rmq:5672]>: Will recover from a network failure (no retry limit)...
Arindam