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

fix: prevent race condition when manually closing channel #644

Merged
merged 1 commit into from Dec 19, 2022

Conversation

milgner
Copy link
Contributor

@milgner milgner commented Dec 15, 2022

In some situations, explicitly calling Channel#close might unregister the channel from the session before the AMQP Close message gets processed.

Backtrace:

Dec 15 16:39:02 ruby[321979]: W, [2022-12-15T16:39:02.427534 #321979]  WARN -- #<Bunny::Session:0x48648 app@localhost:5672, vhost=/, addresses=[localhost:5672]>: TCP connection failed, reconnecting in 5.0 seconds
Dec 15 16:39:02 ruby[321979]: W, [2022-12-15T16:39:02.427582 #321979]  WARN -- #<Bunny::Session:0x48648 app@localhost:5672, vhost=/, addresses=[localhost:5672]>: Will recover from a network failure (no retry limit)...
Dec 15 16:39:02 ruby[321979]: #<Thread:0x00007f3c1ae18540 /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/reader_loop.rb:35 run> terminated with exception (report_on_exception is true):
Dec 15 16:39:02 ruby[321979]: /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/session.rb:1031:in `block in unregister_channel': undefined method `number' for nil:NilClass (NoMethodError)
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/session.rb:1030:in `synchronize'
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/session.rb:1030:in `unregister_channel'
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/session.rb:675:in `ensure in handle_frame'
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/session.rb:675:in `handle_frame'
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/reader_loop.rb:92:in `run_once'
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/reader_loop.rb:39:in `block in run_loop'
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/reader_loop.rb:36:in `loop'
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/reader_loop.rb:36:in `run_loop'

In some situations, explicitly calling `Channel#close` might unregister
the channel from the session before the AMQP Close message gets processed.

Backtrace:

```
Dec 15 16:39:02 ruby[321979]: W, [2022-12-15T16:39:02.427534 #321979]  WARN -- #<Bunny::Session:0x48648 app@localhost:5672, vhost=/, addresses=[localhost:5672]>: TCP connection failed, reconnecting in 5.0 seconds
Dec 15 16:39:02 ruby[321979]: W, [2022-12-15T16:39:02.427582 #321979]  WARN -- #<Bunny::Session:0x48648 app@localhost:5672, vhost=/, addresses=[localhost:5672]>: Will recover from a network failure (no retry limit)...
Dec 15 16:39:02 ruby[321979]: #<Thread:0x00007f3c1ae18540 /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/reader_loop.rb:35 run> terminated with exception (report_on_exception is true):
Dec 15 16:39:02 ruby[321979]: /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/session.rb:1031:in `block in unregister_channel': undefined method `number' for nil:NilClass (NoMethodError)
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/session.rb:1030:in `synchronize'
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/session.rb:1030:in `unregister_channel'
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/session.rb:675:in `ensure in handle_frame'
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/session.rb:675:in `handle_frame'
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/reader_loop.rb:92:in `run_once'
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/reader_loop.rb:39:in `block in run_loop'
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/reader_loop.rb:36:in `loop'
Dec 15 16:39:02 ruby[321979]:         from /opt/app/vendor/bundle/ruby/3.0.0/gems/bunny-2.19.0/lib/bunny/reader_loop.rb:36:in `run_loop'
```
@michaelklishin
Copy link
Member

Thank you! I will slightly alter the wording, merge and publish a patch release.

@michaelklishin michaelklishin merged commit 0d6955f into ruby-amqp:main Dec 19, 2022
@michaelklishin michaelklishin added this to the 2.20.1 milestone Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants