From 1b8601f1ca3f85c8605388f9ca99c0b3d8602b92 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Mon, 18 Jul 2016 23:02:34 +0300 Subject: [PATCH] Raise when calling wait_for_confirms on a closed channel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lib/bunny/channel.rb | 2 ++ .../integration/publisher_confirms_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/bunny/channel.rb b/lib/bunny/channel.rb index 126f17c45..7d5118098 100644 --- a/lib/bunny/channel.rb +++ b/lib/bunny/channel.rb @@ -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 diff --git a/spec/higher_level_api/integration/publisher_confirms_spec.rb b/spec/higher_level_api/integration/publisher_confirms_spec.rb index 3eb422653..76bca7f91 100644 --- a/spec/higher_level_api/integration/publisher_confirms_spec.rb +++ b/spec/higher_level_api/integration/publisher_confirms_spec.rb @@ -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