diff --git a/lib/bunny/session.rb b/lib/bunny/session.rb index df4e27887..95d6a449a 100644 --- a/lib/bunny/session.rb +++ b/lib/bunny/session.rb @@ -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 diff --git a/spec/issues/issue549_spec.rb b/spec/issues/issue549_spec.rb new file mode 100644 index 000000000..3b39b2e04 --- /dev/null +++ b/spec/issues/issue549_spec.rb @@ -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