Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bunny::Channel#close should throw immediately if the channel is already closed by the server #528

carlhoerberg opened this issue Nov 6, 2017 · 6 comments


Copy link

require 'bunny'

b =
ch1 = b.create_channel
ch1.queue("q1").subscribe(exclusive: true) {|d,h,p| }
ch2 = b.create_channel

  ch2.queue("q1").subscribe(exclusive: true) {|d,h,p| }
rescue => e
  puts e.inspect


#<Bunny::AccessRefused: ACCESS_REFUSED - queue 'q1' in vhost '/' in exclusive use>
W, [2017-11-06T15:49:06.381848 #62510]  WARN -- #<Bunny::Session:0x7fd2f2863748 guest@, vhost=/, addresses=[]>: Recovering from connection.close (CHANNEL_ERROR - expected '')
W, [2017-11-06T15:49:06.382057 #62510]  WARN -- #<Bunny::Session:0x7fd2f2863748 guest@, vhost=/, addresses=[]>: Will recover from a network failure (no retry limit)...
/Users/carl/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bunny-2.7.1/lib/bunny/concurrent/continuation_queue.rb:39:in `block in poll': Timeout::Error (Timeout::Error)
        from /Users/carl/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bunny-2.7.1/lib/bunny/concurrent/continuation_queue.rb:30:in `synchronize'
        from /Users/carl/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bunny-2.7.1/lib/bunny/concurrent/continuation_queue.rb:30:in `poll'
        from /Users/carl/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bunny-2.7.1/lib/bunny/session.rb:1343:in `wait_on_continuations'
        from /Users/carl/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bunny-2.7.1/lib/bunny/session.rb:537:in `block in close_channel'
        from /Users/carl/.rbenv/versions/2.4.1/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
        from /Users/carl/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bunny-2.7.1/lib/bunny/session.rb:533:in `close_channel'
        from /Users/carl/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bunny-2.7.1/lib/bunny/channel.rb:236:in `close'
        from bug.rb:12:in `rescue in <main>'
        from bug.rb:8:in `<main>'

shell returned 1
Copy link

This is a race condition we cannot avoid entirely. Server-sent channel.close does not arrive immediately.

Copy link
Contributor Author

I don't know, even adding sleep 1 between rescue and ch2.close raises the exception?

@michaelklishin michaelklishin changed the title Trying to closing a server closed channel throws Timeout::Error exception Bunny::Channel#close should throw immediately if the channel is already closed by the server Nov 6, 2017
@michaelklishin michaelklishin reopened this Nov 6, 2017
Copy link

Bunny::Channel#close doesn't throw early the way most other clients do.

Copy link

@carlhoerberg I'm curious to know if the solution I ended up with in 9df7cb0 makes sense to you. If so I'm happy to release a 2.8.0 very soon.

Thanks again for reporting the issues you encounter.

Copy link
Contributor Author

Super nice!

@michaelklishin michaelklishin added this to the 2.8.0 milestone Dec 18, 2017
Copy link

Shipped in 2.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants