-
Notifications
You must be signed in to change notification settings - Fork 621
long delay in Connection creation on cancellation #1921
Description
Describe the bug
I discovered this while testing. when a tests fails due to some assert I dispose a service that manages my rabbitmq clients. first thing in there is triggering a cancellation token so all initialization attempts are aborted. the rabbitmq client is stuck in this callstack for more than 10 seconds for each client so my tests run into a timeout inside of dispose:
Reproduction steps
whenever the time is less or more it seems to work properly on my machine so you may need to adjust the delay to hit the stack mentioned above.
[TestClass]
public class RabbitRepro
{
private static readonly RabbitMqContainer RabbitMqContainer = new RabbitMqBuilder("rabbitmq:4-management")
.Build();
[TestMethod]
public async Task TestCreateClientWithCancellation()
{
await RabbitMqContainer.StartAsync();
var factory = new ConnectionFactory
{
Uri = new Uri(RabbitMqContainer.GetConnectionString()),
AutomaticRecoveryEnabled = true
};
using var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromMilliseconds(20));
await factory.CreateConnectionAsync(cts.Token);
}
}
Expected behavior
CreateConnectionAsync and its internals should respect the cancellation request and throw as soon as cancellation is requested and not be stuck somewhere for a long time.
what I have seen while debugging is that Channel.DisposeAsync calls CloseAsync which is stuck because its waiting for a response from the server which is not comming because the underlying connection is already closed / not opened yet
Additional context
rabbitmq client 7.2