Skip to content

Commit

Permalink
Preserve channel id allocator after recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelklishin committed Apr 11, 2014
1 parent ba0eee2 commit 6f0cfff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/bunny/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,11 @@ def open_connection
@logger.debug "Heartbeat interval negotiation: client = #{@client_heartbeat}, server = #{connection_tune.heartbeat}, result = #{@heartbeat}"
@logger.info "Heartbeat interval used (in seconds): #{@heartbeat}"

@channel_id_allocator = ChannelIdAllocator.new(@channel_max)
# if there are existing channels we've just recovered from
# a network failure and need to fix the allocated set. See issue 205. MK.
if @channels.empty?
@channel_id_allocator = ChannelIdAllocator.new(@channel_max)
end

@transport.send_frame(AMQ::Protocol::Connection::TuneOk.encode(@channel_max, @frame_max, @heartbeat))
@logger.debug "Sent connection.tune-ok with heartbeat interval = #{@heartbeat}, frame_max = #{@frame_max}, channel_max = #{@channel_max}"
Expand Down
22 changes: 22 additions & 0 deletions spec/higher_level_api/integration/connection_recovery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,26 @@ def ensure_exchange_binding_recovery(ch, source, destination, routing_key = "")
ensure_exchange_binding_recovery(ch, x, x2)
end
end

it "recovers allocated channel ids" do
with_open do |c|
q = "queue#{Time.now.to_i}"
10.times { c.create_channel }
c.queue_exists?(q).should be_false
close_all_connections!
sleep 0.1
c.should_not be_open

wait_for_recovery
c.queue_exists?(q).should be_false
# make sure the connection isn't closed shortly after
# due to "second 'channel.open' seen". MK.
c.should be_open
sleep 0.1
c.should be_open
sleep 0.1
c.should be_open
end
end
end

1 comment on commit 6f0cfff

@michaelklishin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #205.

Please sign in to comment.