Skip to content

Queue auto deletion is not reflected in internal entity cache #579

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

Closed
ionutzp opened this issue Jul 29, 2019 · 6 comments
Closed

Queue auto deletion is not reflected in internal entity cache #579

ionutzp opened this issue Jul 29, 2019 · 6 comments

Comments

@ionutzp
Copy link
Contributor

ionutzp commented Jul 29, 2019

If a queue is auto deleted (a queue declared with auto_delete => true) it is still kept in the cache of ruby bunny Bunny::Channel#queues

This can cause an exception leading to the channel being closed(channel error: NOT_FOUND) when the queue gets deleted by the server by removing it's consumers, redeclared(queue is not recreated in the server) and then rebounded.

@michaelklishin
Copy link
Member

I'm afraid Bunny cannot possibly know if a queue was autodeleted as it cannot track its consumers that may be coming from other connections.

@michaelklishin michaelklishin changed the title Queue auto deletion not reflected in internal cache of ruby bunny Queue auto deletion is not reflected in internal entity cache Jul 30, 2019
@michaelklishin
Copy link
Member

This is also the case for RabbitMQ Java client, for example: it will try to invalidate known "cache" entries that are auto-delete but it is only able to do so for queues and consumers managed on a single connection (it used to be a channel). There is no way a connection can know what's happening to consumers on other connections or in other processes.

Consider not sharing auto-delete queues or using passive declares where appropriate. No sharing means no queue "state" incoherencies.

@ionutzp
Copy link
Contributor Author

ionutzp commented Jul 30, 2019

Hi @michaelklishin i am using a single connection, and just deleting the single consumer of an auto delete queue. The server then deletes the queue but i couldn't seem to find anywhere in the code of ruby-bunny where the queue cache would be updated.

@michaelklishin
Copy link
Member

As I explained above, Bunny cannot really get much insight into those events. It only has a chance to "correct" such discrepancies during connection recovery. RabbitMQ Java client is the most advanced in this area: it invalidates entries in its cache of known entities based on some of their
attributes but only for operations that are performed on the same connection. In other words, if you cancel a consumer by closing a channel or using management tools, no client can discover that and update its cache.

AutorecoveringConnection and AutorecoveringChannel demonstrate the idea.

Bunny could do something similar and the cache can be connection-wide (it is per-channel).
That still would not eliminate every scenario where the server decides to delete an entity for reasons that the client has no way to observe. Queue TTL is one obvious example.

@michaelklishin
Copy link
Member

I'd consider a PR that adds an option that bypasses the cache for Bunny::Channel#queue and Bunny::Channel#exchange. Perhaps that would make it possible for you to sacrifice some efficiency but avoid running into operations on already deleted entities. So feel free to investigate this, it should be a fairly straightforward feature to add.

@ionutzp
Copy link
Contributor Author

ionutzp commented Jul 30, 2019

Ok I understand. I was under the impression that ruby-bunny also implements: _ it invalidates entries in its cache of known entities based on some of their
attributes_. As for if you cancel a consumer by closing a channel or using management tools, no client can discover that and update its cache. i would have no expectations there and my use case is explicitly cancelling a consumer. I will keep the PR in mind. Thanks for the information.

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

No branches or pull requests

2 participants