Skip to content

Commit

Permalink
Issue ruby-amqp#549: Transition connection to closed state when recov…
Browse files Browse the repository at this point in the history
…ery attempts

are exhausted

When the RabbitMQ server goes down, the session attempts to continually
reconnect, only stopping once the recovery_attempts threshold is met (or
forever is this parameter is not provided). In the former case, there
are no exceptions raised to indicate to clients that new messages are
not being processed. This patch provides that by initiating close
from the session, which will close related channels and the reader
loop. Then, an exception will be thrown when subsequent operations are
performed.
  • Loading branch information
arlandism committed Jul 27, 2018
1 parent dd8c9c0 commit 0e77347
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/bunny/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ def recover_from_network_failure
end
else
@logger.error "Ran out of recovery attempts (limit set to #{@max_recovery_attempts})"
self.close
end
end

Expand Down
30 changes: 30 additions & 0 deletions spec/issues/issue549_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'spec_helper'

describe Bunny::Session do
context 'when retry attempts have been exhausted' do
let(:io) { StringIO.new } # keep test output clear

def create_session
described_class.new(
host: 'fake.host',
recovery_attempts: 0,
connection_timeout: 0,
network_recovery_interval: 0,
logfile: io,
)
end

it 'closes the session' do
session = create_session
session.handle_network_failure(StandardError.new)
expect(session.closed?).to be true
end

it 'stops the reader loop' do
session = create_session
reader_loop = session.reader_loop
session.handle_network_failure(StandardError.new)
expect(reader_loop.stopping?).to be true
end
end
end

0 comments on commit 0e77347

Please sign in to comment.