EasyNetQ / EasyNetQ

An easy to use .NET API for RabbitMQ
http://easynetq.com
MIT License
2.9k stars 750 forks source link

Connection errors to RMQ return unclear exception messages. #1620

Open foggerty opened 1 year ago

foggerty commented 1 year ago

Describe the bug When EasyNetQ is unable to connect to RMQ (because, say, the user name is incorrect) it raises an exception with the message "A task was cancelled" instead of something indicating the problem.

[edit]I realise that EasyNetQ has a lazy connection/retry model, but if the user-name is incorrect, no amount of retrying will make a difference. So a fix for this depends on the errors that RMQ returns when connecting.[/edit]

To Reproduce

// Add both EasyNetQ and NewtonSoft.JSON to the project before building.

using EasyNetQ;

IBus _bus;

void tst(string str)
{
    Console.WriteLine("Here!");
}

// Change the host or username to something incorect and you'll get an exception with the message "A task was cancelled".
_bus = RabbitHutch.CreateBus("host=HOST_NAME;virtualHost=VIRTUAL_HOST;username=USER_NAME;password=PASSWORD");
_bus.SendReceive.Receive<string>("QueueName", tst, new CancellationToken());

Console.WriteLine("Nothing exploded, hooray!");

Console.ReadLine();

Expected behavior Any exception that arises because of a connection error, should clearly state so.

Please complete the following information):

Additional context This is in ,NET 6.

Pliner commented 1 year ago

Hey @foggerty,

Thanks for reporting this.

[edit]I realise that EasyNetQ has a lazy connection/retry model, but if the user-name is incorrect, no amount of retrying will make a difference. So a fix for this depends on the errors that RMQ returns when connecting.[/edit]

In the case of incorrect login/password, we could detect such a case, stop retrying and throw an exception.

For the case of incorrect hostname specified, I am afraid we should retry, because we can`t distinguish whether it is a transient error(a host is unavailable) or a permanent one(a wrong non-existing host is specified).

foggerty commented 1 year ago

Doh, good point re hostname :-)