Skip to content

Commit

Permalink
ConsumerWorkPool: don't wait for consumer shutdown if the pool isn't …
Browse files Browse the repository at this point in the history
…active

Fixes #438.
  • Loading branch information
michaelklishin committed Oct 21, 2016
1 parent 052ebc6 commit 24c2358
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/bunny/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,9 @@ def basic_cancel(consumer_tag)
@last_basic_cancel_ok = wait_on_continuations
end

@work_pool.shutdown(true) unless any_consumers?
# reduces thread usage for channels that don't have any
# consumers
@work_pool.shutdown(true) unless self.any_consumers?

@last_basic_cancel_ok
end
Expand Down
3 changes: 2 additions & 1 deletion lib/bunny/consumer_work_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def busy?
end

def shutdown(wait_for_workers = false)
was_running = running?
@running = false

@size.times do
Expand All @@ -65,7 +66,7 @@ def shutdown(wait_for_workers = false)
end
end

return unless wait_for_workers && @shutdown_timeout
return if !(wait_for_workers && @shutdown_timeout && was_running)

@shutdown_mutex.synchronize do
@shutdown_conditional.wait(@shutdown_mutex, @shutdown_timeout)
Expand Down
8 changes: 6 additions & 2 deletions spec/higher_level_api/integration/basic_cancel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@
sleep 1.0

ch = connection.create_channel
ch.confirm_select
ch.default_exchange.publish("", :routing_key => queue_name)
sleep 0.7
ch.wait_for_confirms
sleep 0.5

consumer.cancel
sleep 1.0
Expand Down Expand Up @@ -126,8 +128,10 @@
sleep 1.0

ch = connection.create_channel
ch.confirm_select
ch.default_exchange.publish("", :routing_key => queue_name)
sleep 0.7
ch.wait_for_confirms
sleep 0.5

consumer.cancel
sleep 1.0
Expand Down

0 comments on commit 24c2358

Please sign in to comment.