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

x-consistent-hash implementation has divide by zero error when no routing key is specified #127

Open
RedMu opened this issue Jul 1, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@RedMu
Copy link
Contributor

RedMu commented Jul 1, 2020

No description provided.

@RedMu RedMu closed this as completed Jul 1, 2020
@RedMu RedMu reopened this Jul 1, 2020
@RedMu
Copy link
Contributor Author

RedMu commented Jul 1, 2020

Had to mock up a test case to prove this, ConsistentHashExchange.routingKeyToWeight should throw an IllegalArgumentException rather than trying to return the Hashcode of a non numeric routing key which is not possible on RabbitMQ. When no routing key is specified the weight is returned as 0 which later fails with a divide by zero in selectReceiver.

RedMu added a commit to RedMu/rabbitmq-mock that referenced this issue Jul 1, 2020
@ledoyen
Copy link
Contributor

ledoyen commented Jul 3, 2020

Hi @RedMu, thanks for spotting this.

I agree that no ArithmeticException should be thrown when publishing to a x-consistent-hash bound with a routingKey hashed to 0.

However I wonder what is the behavior of RabbitMq in this situation ?

I will make the test whenever I can find the time to do it.

@RedMu
Copy link
Contributor Author

RedMu commented Jul 3, 2020

Hi Ledoyen,

I made a quick test, when you try to bind without a binding key you get an IOException with the following:

2020-07-03 19:17:18,815 ERROR org.springframework.amqp.rabbit.connection.CachingConnectionFactory [AMQP Connection 127.0.0.1:5672] : Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - The binding key must be an integer: <<>>, class-id=50, method-id=20)

It is not possible to create a binding through the management console without a binding key.

It's actually an IOException that is thrown by the rabbitmq java client code - but it seemed more logical to have an IllegalArgumentException for the mock library.

@ledoyen ledoyen added the bug Something isn't working label Jul 21, 2020
RedMu added a commit to RedMu/rabbitmq-mock that referenced this issue Jul 21, 2020
RedMu added a commit to RedMu/rabbitmq-mock that referenced this issue Jul 21, 2020
RedMu added a commit to RedMu/rabbitmq-mock that referenced this issue Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants