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

Closed
carlhoerberg opened this Issue Nov 6, 2017 · 6 comments

Comments

Projects
None yet
2 participants
@carlhoerberg
Contributor

carlhoerberg commented Nov 6, 2017

require 'bunny'

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

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

Result:

#<Bunny::AccessRefused: ACCESS_REFUSED - queue 'q1' in vhost '/' in exclusive use>
W, [2017-11-06T15:49:06.381848 #62510]  WARN -- #<Bunny::Session:0x7fd2f2863748 guest@127.0.0.1:5672, vhost=/, addresses=[127.0.0.1:5672]>: Recovering from connection.close (CHANNEL_ERROR - expected 'channel.open')
W, [2017-11-06T15:49:06.382057 #62510]  WARN -- #<Bunny::Session:0x7fd2f2863748 guest@127.0.0.1:5672, vhost=/, addresses=[127.0.0.1:5672]>: 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
@michaelklishin

This comment has been minimized.

Show comment
Hide comment
@michaelklishin

michaelklishin Nov 6, 2017

Member

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

Member

michaelklishin commented Nov 6, 2017

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

@carlhoerberg

This comment has been minimized.

Show comment
Hide comment
@carlhoerberg

carlhoerberg Nov 6, 2017

Contributor

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

Contributor

carlhoerberg commented Nov 6, 2017

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

@michaelklishin michaelklishin changed the title from Trying to closing a server closed channel throws Timeout::Error exception to 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

@michaelklishin

This comment has been minimized.

Show comment
Hide comment
@michaelklishin

michaelklishin Nov 6, 2017

Member

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

Member

michaelklishin commented Nov 6, 2017

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

@michaelklishin

This comment has been minimized.

Show comment
Hide comment
@michaelklishin

michaelklishin Dec 18, 2017

Member

@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.

Member

michaelklishin commented Dec 18, 2017

@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.

@carlhoerberg

This comment has been minimized.

Show comment
Hide comment
@carlhoerberg

carlhoerberg Dec 18, 2017

Contributor

Super nice!

Contributor

carlhoerberg commented Dec 18, 2017

Super nice!

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

@michaelklishin

This comment has been minimized.

Show comment
Hide comment
@michaelklishin

michaelklishin Dec 18, 2017

Member

Shipped in 2.8.0.

Member

michaelklishin commented Dec 18, 2017

Shipped in 2.8.0.

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