Skip to content

Commit

Permalink
Raise when calling wait_for_confirms on a closed channel
Browse files Browse the repository at this point in the history
If a channel is already closed it will receive no new frames and waiting
for confirmations will most likely hang and timeout unless the frames
were somehow already received.

If one wishes to wait for confirmations it’s probably the case that the
user doesn’t expect the channel to be closed and we should notify them
about it by failing early. A channel might be closed by RabbitMQ in case
of a channel-level error for example due to a publishing error.
  • Loading branch information
mitio committed Jul 18, 2016
1 parent ab03923 commit 1b8601f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/bunny/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,8 @@ def wait_on_basic_get_continuations

# @private
def wait_on_confirms_continuations
raise_if_no_longer_open!

if @connection.threaded
t = Thread.current
@threads_waiting_on_confirms_continuations << t
Expand Down
12 changes: 12 additions & 0 deletions spec/higher_level_api/integration/publisher_confirms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@
}.not_to raise_error

end

it "raises an error when called on a closed channel" do
ch = connection.create_channel

ch.confirm_select

ch.close

expect {
ch.wait_for_confirms
}.to raise_error(Bunny::ChannelAlreadyClosed)
end
end

context "when some of the messages get nacked" do
Expand Down

0 comments on commit 1b8601f

Please sign in to comment.